-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongodb.js
More file actions
71 lines (62 loc) · 1.57 KB
/
mongodb.js
File metadata and controls
71 lines (62 loc) · 1.57 KB
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
// CRUD operations
const { MongoClient, ObjectID } = require("mongodb");
const connectionURL = "mongodb://127.0.0.1:27017";
const databaseName = "task-manager";
MongoClient.connect(connectionURL, { useNewURLParser: true }, (err, client) => {
if (err) {
return console.log("Unable to connect DB!");
}
const db = client.db(databaseName);
/* Delete Many operator */
db.collection("tasks")
.deleteMany({ desc: "Finalise PHP PPT" })
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
/* Testing delete operator of MongoDB */
// db.collection("users")
// .deleteMany({ age: 33 })
// .then((res) => {
// console.log(res);
// })
// .catch((err) => {
// console.log(err);
// });
/* Testing UpdateMany operator of MongoDB */
// db.collection("tasks")
// .updateMany(
// { complete: false },
// {
// $set: {
// complete: true,
// },
// }
// )
// .then((res) => {
// console.log("Success: " + res);
// })
// .catch((err) => {
// console.log("Error: " + err);
// });
/* Tested MongoDB promise and basic update operators */
// db.collection("users")
// .updateOne(
// {
// _id: new ObjectID("6197ac869f88962b2ab1e910"),
// },
// {
// $inc: {
// age: 2,
// },
// }
// )
// .then((res) => {
// console.log("Update successful: " + res);
// })
// .catch((err) => {
// console.log("Error in updating : " + err);
// });
});