-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongodb.fine-update-delete.js
More file actions
74 lines (70 loc) · 2.12 KB
/
Copy pathmongodb.fine-update-delete.js
File metadata and controls
74 lines (70 loc) · 2.12 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
72
73
const mongodbFineUpdateDelete = require('mongodb');
const { MongoClient, ObjectID } = mongodbFineUpdateDelete;
const connectionUrl = "mongodb://127.0.0.1:27017";
const databaseName = "task-manager";
// const id = new ObjectID();
// console.log('id',id, id.getTimestamp());
MongoClient.connect(connectionUrl, {
useNewUrlParser: true
}, (error, client) => {
if (error) {
return console.error('unable to connect', error);
}
const db = client.db(databaseName);
// db.collection('users').findOne({_id: ObjectID("60147137bcf2902236246d68")}, (error, result) => {
// if (error) return console.error(error);
// console.log(result);
// });
// db.collection('users').find({age: 41}).toArray((error, result) => {
// if (error) return console.error(error);
// console.log(result);
// });
// db.collection('users').find({age: 41}).count((error, result) => {
// if (error) return console.error(error);
// console.log(result);
// });
// db.collection('tasks').findOne({_id: ObjectID("601473f4ecea632288c0c5e5")}, (error, result) => {
// if (error) return console.error(error);
// console.log(result);
// });
// db.collection('tasks').find({completed: false}).toArray((error, result) => {
// if (error) return console.error(error);
// console.log(result);
// });
// db.collection('users').updateOne({
// _id: ObjectID("60146fffd234ec220bdff382")
// }, {
// $inc: {
// age: 1
// }
// }).then(result => {
// console.log(result);
// }).catch((error) => {
// console.error(error);
// });
// db.collection('tasks').updateMany({
// completed: false
// }, {
// $set: {
// completed: true
// }
// }).then(result => {
// console.log(result);
// }).catch((error) => {
// console.error(error);
// });
// db.collection('users').deleteMany({
// age: 41
// }).then(result => {
// console.log(result);
// }).catch((error) => {
// console.error(error);
// });
db.collection('tasks').deleteOne({
description: "study mongodb"
}).then(result => {
console.log(result);
}).catch((error) => {
console.error(error);
});
});