-
Notifications
You must be signed in to change notification settings - Fork 4
/
crud.js
87 lines (75 loc) · 2.26 KB
/
crud.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// CRUD: Create, Read, Update, Delete
const { MongoClient, ObjectId } = require('mongodb');
const connectionURI = "mongodb://127.0.0.1:27017";
const database = "task-manager";
const id = new ObjectId();
//console.log(id);
//console.log(id.getTimestamp());
MongoClient.connect(connectionURI, {useNewUrlParser:true}, (error, client) => {
if(error){
return console.log("Error establishing connection...");
}
const db = client.db(database);
db.collection('users').deleteMany({
age: 31
}).then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
/*db.collection('tasks').updateMany({
completed:false
},{
$set:{
completed: true
}
}).then((result)=>{
console.log(result);
}).catch((error)=>{
console.log(error);
});*/
/*db.collection('users').update({
_id:new ObjectId("5ce293c0511eb823016c9fa0")
},{
$set:{name:"Hardy Wilson"}
}).then((result)=>{
console.log(result);
}).catch((error)=>{
console.log(error);
});*/
/*db.collection('users').findOne({_id:new ObjectId("5ce2917252a5a721aafed448")}, (error, result) => {
console.log(result);
});
db.collection('users').find({age:32}).toArray((error, result) => {
console.log(result);
});*/
/*db.collection('users').insertOne({
_id: id,
name: 'Hardev1 Sharma1',
age: 31
}, (error, result) => {
if(error){
return console.log("Unable to insert document...");
}
console.log(result.ops);
});*/
/*db.collection('users').insertMany([
{name: 'Sunil Kumar', age: 25},
{name: 'Harry', age: 33}
], (error, result) => {
if(error){
return console.log('Unable to insert documents...');
}
console.log(result.ops);
});*/
/*db.collection('tasks').insertMany([
{description: 'House Cleaning', completed: true},
{description: 'Gardening', completed: false},
{description: 'Run Tution Classes', completed: true}
], (error, result) => {
if(error){
return console.log('Data insertion error!');
}
console.log(result.ops);
});*/
});