-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongodb.js
35 lines (28 loc) · 916 Bytes
/
mongodb.js
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
29
30
31
32
33
34
35
// CRUD Create Read Update Delete
const mongodb = require('mongodb')
const MongoClient = mongodb.MongoClient
const ObjectId = mongodb.ObjectId
//Shorthand Expression
// const { MongoClient , ObjectId } =require('mongodb')
const connectionURL = 'mongodb://127.0.0.1:27017'
const databaseName = 'task-manager'
MongoClient.connect(connectionURL, { useNewUrlParser : true } , (error , client) => {
if(error) {
return console.log('Unable to connect to Database !');
}
const db = client.db(databaseName)
// db.collection('Users').deleteMany({
// age : 20
// }).then((result) =>{
// console.log(result);
// }).catch((error)=>{
// console.log(error);
// })
db.collection('Tasks').deleteOne({
description : "Go to Birthday"
}).then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
})
})