-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongodb.js
45 lines (40 loc) · 1.05 KB
/
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
39
40
41
42
43
44
45
//CRUD operqations explore
const mongodb= require('mongodb')
const MongoClient= mongodb.MongoClient
const connectionURL= 'mongodb://127.0.0.1:27017'
const dbName= 'tasks'
MongoClient.connect(connectionURL, {useUnifiedTopology: true }, (error, client) =>{
if(error) {
return console.log('Unable to connect')
}
const db= client.db(dbName)
db.collection('users').insertMany ([
{
name:'Howard',
age:'28'
},{
name:'Derek',
age:'34'
}
], (error, result) =>{
if(error){
console.log('Error while inserting users.')
}
console.log(result.ops)
})
db.collection('tasks').insertMany([
{
descrption:'buy groceries',
status:'done'
},
{
descrption:'go to the dentist',
status:'pending'
}
], (error, result) =>{
if(error){
console.log('Error while inserting tasks.')
}
console.log(result.ops)
})
})