-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongodb.js
More file actions
28 lines (22 loc) · 791 Bytes
/
mongodb.js
File metadata and controls
28 lines (22 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var mongodb = require('mongodb');
// var MongoClient = mongodb.MongoClient; var ObjectID = mongodb.ObjectID;
var {MongoClient, ObjectID} = require('mongodb');
var connectionURL = 'mongodb://127.0.0.1:27017';
var databaseName = 'task-manager';
var id = new ObjectID();
console.log(id.getTimestamp());
MongoClient.connect(connectionURL,{useNewUrlParser:true, useUnifiedTopology: true},(error, client)=>{
if(error){
return console.log("Unable to connect");
}
//The database that we are trying to maniplulate
const db = client.db(databaseName);
var updatePromise = db.collection('users').deleteMany({
age:20
});
updatePromise.then((result)=>{
console.log(result.deletedCount);
}).catch((err)=>{
console.log(err);
});
});