-
Notifications
You must be signed in to change notification settings - Fork 0
/
crud.mongodb.js
100 lines (84 loc) · 1.68 KB
/
crud.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
// CRUD Operations
use("CRUDdb")
console.log(db)
// CREATE
db.createCollection("courses")
db.courses.insertOne({
name: "Taha is GENIUS.",
price: 0,
assignments: 12,
projects: 45
})
db.courses.insertMany([
{
"name": "Taha entry 1",
"price": 0,
"assignments": 5,
"projects": 10
},
{
"name": "Taha entry 2",
"price": 10,
"assignments": 10,
"projects": 20
},
{
"name": "Taha entry 3",
"price": 20,
"assignments": 15,
"projects": 30
},
{
"name": "Taha entry 4",
"price": 30,
"assignments": 20,
"projects": 40
},
{
"name": "Taha entry 5",
"price": 40,
"assignments": 25,
"projects": 50
},
{
"name": "Taha entry 6",
"price": 50,
"assignments": 30,
"projects": 60
},
{
"name": "Taha entry 7",
"price": 60,
"assignments": 35,
"projects": 70
},
{
"name": "Taha entry 8",
"price": 70,
"assignments": 40,
"projects": 80
},
{
"name": "Taha entry 9",
"price": 80,
"assignments": 45,
"projects": 90
},
{
"name": "Taha entry 10",
"price": 90,
"assignments": 50,
"projects": 100
}
])
// READ
let a = db.courses.find({price: 0})
console.log(a.toArray())
console.log(a.count())
let b = db.courses.findOne({price: 0})
console.log(b)
// UPDATE
db.courses.updateOne({price: 100}, {$set: {price: 10}})
db.courses.updateMany({price: 10}, {$set: {price: 1000}})
// DELETE
db.courses.deleteMany({price: {$gte: 0}})