-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmongodb.js
38 lines (32 loc) · 979 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
36
37
38
//! CRUD Create Read Update Delete
/**
*
* to add connection ./mongodb/bin/mongod --dbpath=/home/farees/mongodb-data
* to open robo mongo run robomongo
*
*/
/* 1 way */
// const mongodb = require('mongodb')
// const MongoClient = mongodb.MongoClient
// const ObjectID = mongodb.ObjectID
/* 2nd way */
const { MongoClient,ObjectID } = require('mongodb')
const connectionURL = 'mongodb://127.0.0.1:27017'
const databaseName = 'task-manager'
const id = new ObjectID()
// console.log(id)
// console.log(id.id)
// console.log(id.toHexString().length)
MongoClient.connect(connectionURL, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, useFindAndModify: false }, (error,client)=>{
if(error){
return console.log('unable to connect to database')
}
const db = client.db(databaseName)
db.collection('users').deleteOne({
name:"Shahzeb"
}).then((res)=>{
console.log(res.deletedCount)
}).catch((err)=>{
console.log(err)
})
})