Skip to content

Commit 72183ed

Browse files
authored
Update Readme.md
1 parent 7a23f23 commit 72183ed

File tree

1 file changed

+78
-42
lines changed

1 file changed

+78
-42
lines changed

Readme.md

Lines changed: 78 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,110 @@
1-
# mongodb_cheatsheet
2-
Handlful cheatsheet which you can carry while using mongodb no need to search each commands on browser
1+
Certainly! Below is the README content for your MongoDB cheatsheet repository:
32

4-
MongoDB Shell Cheatsheet
3+
---
54

6-
Basic Commands:
5+
# MongoDB Cheatsheet
76

8-
1. Start MongoDB Shell:
7+
A handy cheatsheet for MongoDB users to reference basic and advanced commands without the need to search for each command online.
8+
9+
## MongoDB Shell Cheatsheet
10+
11+
### Basic Commands
12+
13+
1. **Start MongoDB Shell:**
14+
```
915
mongo
16+
```
1017

11-
2. View Databases:
18+
2. **View Databases:**
19+
```
1220
show dbs
21+
```
1322

14-
3. Switch Database:
23+
3. **Switch Database:**
24+
```
1525
use mydatabase
26+
```
1627

17-
4. View Collections in Current Database:
28+
4. **View Collections in Current Database:**
29+
```
1830
show collections
31+
```
1932

20-
5. Create Database:
33+
5. **Create Database:**
34+
```
2135
use mydatabase
36+
```
2237

23-
6. Create Collection:
38+
6. **Create Collection:**
39+
```
2440
db.createCollection("mycollection")
41+
```
2542

26-
7. Insert Document into Collection:
43+
7. **Insert Document into Collection:**
44+
```
2745
db.mycollection.insertOne({ key: "value" })
46+
```
2847

29-
8. Find Documents in Collection:
48+
8. **Find Documents in Collection:**
49+
```
3050
db.mycollection.find()
51+
```
3152

32-
9. Update Document in Collection:
53+
9. **Update Document in Collection:**
54+
```
3355
db.mycollection.updateOne({ key: "value" }, { $set: { key: "new value" } })
56+
```
3457

35-
10. Remove Document from Collection:
58+
10. **Remove Document from Collection:**
59+
```
3660
db.mycollection.deleteOne({ key: "value" })
61+
```
3762
38-
11. Drop Collection:
63+
11. **Drop Collection:**
64+
```
3965
db.mycollection.drop()
66+
```
4067
41-
12. Drop Database:
68+
12. **Drop Database:**
69+
```
4270
use mydatabase
4371
db.dropDatabase()
72+
```
4473
74+
### Advanced Commands
4575
46-
Advanced Commands:
76+
13. **Index Management:**
77+
- Create Index: `db.mycollection.createIndex({ key: 1 })`
78+
- List Indexes: `db.mycollection.getIndexes()`
79+
- Drop Index: `db.mycollection.dropIndex("indexName")`
4780
48-
13. Index Management:
49-
- Create Index: db.mycollection.createIndex({ key: 1 })
50-
- List Indexes: db.mycollection.getIndexes()
51-
- Drop Index: db.mycollection.dropIndex("indexName")
52-
53-
14. Aggregation Framework:
81+
14. **Aggregation Framework:**
82+
```
5483
db.mycollection.aggregate([...])
84+
```
85+
86+
15. **Data Import and Export:**
87+
- Import Data from JSON: `mongoimport --db mydatabase --collection mycollection --file data.json`
88+
- Export Data to JSON: `mongoexport --db mydatabase --collection mycollection --out data.json`
89+
90+
16. **User Management:**
91+
- Create User: `db.createUser({ user: "username", pwd: "password", roles: ["readWrite"] })`
92+
- List Users: `db.getUsers()`
93+
- Drop User: `db.dropUser("username")`
94+
95+
17. **Replica Sets and Sharding:**
96+
- Initialize Replica Set: `rs.initiate()`
97+
- Add Replica Set Member: `rs.add("hostname:port")`
98+
- Enable Sharding on Database: `sh.enableSharding("mydatabase")`
99+
- Shard Collection: `sh.shardCollection("mydatabase.mycollection", { shardKey: 1 })`
100+
101+
18. **Server Administration:**
102+
- Server Status: `db.serverStatus()`
103+
- Current Operations: `db.currentOp()`
104+
- Server Logs: `db.getLog("global")`
105+
106+
Feel free to copy and paste these commands into your MongoDB terminal for quick reference!
107+
108+
---
55109
56-
15. Data Import and Export:
57-
- Import Data from JSON: mongoimport --db mydatabase --collection mycollection --file data.json
58-
- Export Data to JSON: mongoexport --db mydatabase --collection mycollection --out data.json
59-
60-
16. User Management:
61-
- Create User: db.createUser({ user: "username", pwd: "password", roles: ["readWrite"] })
62-
- List Users: db.getUsers()
63-
- Drop User: db.dropUser("username")
64-
65-
17. Replica Sets and Sharding:
66-
- Initialize Replica Set: rs.initiate()
67-
- Add Replica Set Member: rs.add("hostname:port")
68-
- Enable Sharding on Database: sh.enableSharding("mydatabase")
69-
- Shard Collection: sh.shardCollection("mydatabase.mycollection", { shardKey: 1 })
70-
71-
18. Server Administration:
72-
- Server Status: db.serverStatus()
73-
- Current Operations: db.currentOp()
74-
- Server Logs: db.getLog("global")
110+
You can copy the content and save it into your README.md file in your MongoDB cheatsheet repository. This will provide users with an easy-to-access reference for MongoDB commands.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy