-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMongoDB_Basics
142 lines (136 loc) · 3.52 KB
/
MongoDB_Basics
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
student@student-Veriton-M200-H61:~$ mongo
MongoDB shell version v3.6.8
> show dbs;
104 0.000GB
Adi 0.000GB
product 0.000GB
sample 0.000GB
test 0.000GB
> use xyz;
switched to db xyz
> show collections;
> use product;
switched to db product
> show collections;
Product
> use sample;
switched to db sample
> show collections;
bick
movie
product
> use xyz;
switched to db xyz
> db.emp.insert({eno:123,ename:"sai",esal:322.23});
WriteResult({ "nInserted" : 1 })
> db.emp.insert({eno:124,ename:"Sai ram",esal:522.23,edesg:"Asst Prof"},{eno:231,edept:"Comp",skillset:["c","c++","DBMS"]});
WriteResult({ "nInserted" : 1 })
>
> db.emp.find();
{ "_id" : ObjectId("6449fff198d0188b1552fb6b"), "eno" : 123, "ename" : "sai", "esal" : 322.23 }
{ "_id" : ObjectId("644a00c698d0188b1552fb6c"), "eno" : 124, "ename" : "Sai ram", "esal" : 522.23, "edesg" : "Asst Prof" }
> db.emp.insert({eno:231,edept:"Comp",skillset:["c","c++","DBMS"]});
WriteResult({ "nInserted" : 1 })
> db.emp.find();
{ "_id" : ObjectId("6449fff198d0188b1552fb6b"), "eno" : 123, "ename" : "sai", "esal" : 322.23 }
{ "_id" : ObjectId("644a00c698d0188b1552fb6c"), "eno" : 124, "ename" : "Sai ram", "esal" : 522.23, "edesg" : "Asst Prof" }
{ "_id" : ObjectId("644a013298d0188b1552fb6d"), "eno" : 231, "edept" : "Comp", "skillset" : [ "c", "c++", "DBMS" ] }
> db.emp.find().pretty();
{
"_id" : ObjectId("6449fff198d0188b1552fb6b"),
"eno" : 123,
"ename" : "sai",
"esal" : 322.23
}
{
"_id" : ObjectId("644a00c698d0188b1552fb6c"),
"eno" : 124,
"ename" : "Sai ram",
"esal" : 522.23,
"edesg" : "Asst Prof"
}
{
"_id" : ObjectId("644a013298d0188b1552fb6d"),
"eno" : 231,
"edept" : "Comp",
"skillset" : [
"c",
"c++",
"DBMS"
]
}
> db.emp.find();
{ "_id" : ObjectId("6449fff198d0188b1552fb6b"), "eno" : 123, "ename" : "sai", "esal" : 322.23 }
{ "_id" : ObjectId("644a00c698d0188b1552fb6c"), "eno" : 124, "ename" : "Sai ram", "esal" : 522.23, "edesg" : "Asst Prof" }
{ "_id" : ObjectId("644a013298d0188b1552fb6d"), "eno" : 231, "edept" : "Comp", "skillset" : [ "c", "c++", "DBMS" ] }
> db.emp.find().pretty();
{
"_id" : ObjectId("6449fff198d0188b1552fb6b"),
"eno" : 123,
"ename" : "sai",
"esal" : 322.23
}
{
"_id" : ObjectId("644a00c698d0188b1552fb6c"),
"eno" : 124,
"ename" : "Sai ram",
"esal" : 522.23,
"edesg" : "Asst Prof"
}
{
"_id" : ObjectId("644a013298d0188b1552fb6d"),
"eno" : 231,
"edept" : "Comp",
"skillset" : [
"c",
"c++",
"DBMS"
]
}
> db.emp.find({eno:124},{ename:1});
{ "_id" : ObjectId("644a00c698d0188b1552fb6c"), "ename" : "Sai ram" }
> db.emp.find({eno:124});
{ "_id" : ObjectId("644a00c698d0188b1552fb6c"), "eno" : 124, "ename" : "Sai ram", "esal" : 522.23, "edesg" : "Asst Prof" }
> db.emp.find({eno:124}).pretty();
{
"_id" : ObjectId("644a00c698d0188b1552fb6c"),
"eno" : 124,
"ename" : "Sai ram",
"esal" : 522.23,
"edesg" : "Asst Prof"
}
> db.emp.find({eno:124},{esal:1}).pretty();
{ "_id" : ObjectId("644a00c698d0188b1552fb6c"), "esal" : 522.23 }
> db.emp.find({eno:124},{esal:1,ename:1}).pretty();
{
"_id" : ObjectId("644a00c698d0188b1552fb6c"),
"ename" : "Sai ram",
"esal" : 522.23
}
> db.emp.find({eno:124},{esal:0}).pretty();
{
"_id" : ObjectId("644a00c698d0188b1552fb6c"),
"eno" : 124,
"ename" : "Sai ram",
"edesg" : "Asst Prof"
}
> db.emp.remove({eno:124});
WriteResult({ "nRemoved" : 1 })
> db.emp.find().pretty();
{
"_id" : ObjectId("6449fff198d0188b1552fb6b"),
"eno" : 123,
"ename" : "sai",
"esal" : 322.23
}
{
"_id" : ObjectId("644a013298d0188b1552fb6d"),
"eno" : 231,
"edept" : "Comp",
"skillset" : [
"c",
"c++",
"DBMS"
]
}
>