-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongodb.js
More file actions
71 lines (55 loc) · 1.95 KB
/
Copy pathmongodb.js
File metadata and controls
71 lines (55 loc) · 1.95 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
// const mongodb = require('mongodb');
// const mongoClient = mongodb.MongoClient
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 to database!');
}
const db = client.db(databaseName)
// db.collection('users').findOne({age: 21}, (err, user)=>{
// if (err) {
// return console.log("Unable to fetch");
// }
// return console.log(user)
// });
// db.collection('users').find({age: 21}).toArray((err, users)=>{
// if (err) {
// return console.log("Unable to fetch")
// }
// return console.log(users)
// })
// db.collection('tasks').findOne({_id: new ObjectID("6225f6f412e1d539df26ed34")}, (err, task)=>{
// console.log(task);
// })
// db.collection('tasks').find({completed: true}).toArray((err, tasks)=>{
// console.log(tasks);
// })
// db.collection('users').updateOne({
// _id: new ObjectID("6225fbc086f7d17c90bf667b")
// }, {
// // $set:{name: "Yahya"}
// $inc:{age: 1}
// }).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')
// .deleteMany({age: {$gt: 25}})
// .then((result)=>{
// console.log(result);
// })
// .catch((error)=>{
// console.log(error);
// })
console.log('Connected to database successfully!');
})