MongoDB Shell Cheat Sheet
 Share
The version of the browser you are using is no longer supported. Please upgrade to a supported browser.Dismiss

 
View only
 
 
ABCDEFGHIJKLMNOPQRST
1
CommandExample syntaxNotesLinks
2
Database Commands
3
Show the current databasedb
4
List (show) databasesshow dbs
5
Create or switch to a new/different databaseuse some_other_dbA database will not be saved until it contains a collection with a document
6
7
Collection Commands
8
List (show) collections in the current databaseshow collections
9
Show documents in a collection named bluedb.blue.find()
10
Drop a collection named bluedb.blue.drop()
11
12
Document Commands
13
Create a temporary document variablej = { "Author": "Jared" }
14
Insert a tempory document (j) into a collectiondb.some_collection.insert(j)This operation is performed on the current db. You can see the current db by typing db
15
16
Create a Replica Set
17
Show replica set configurationrs.conf()
18
Show replica set statusrs.status()
19
Allow reading from slavesrs.slaveOk()
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
Loading...
 
 
 
Sheet1