MongoDB Shell (mongosh) — NoSQL Database from CLI
Query and manage your MongoDB database directly from the terminal:
Connect & Explore:
```javascript
mongosh "mongodb://localhost:27017"
use myapp
show collections
`
CRUD Operations:
```javascript
// Create
db.users.insertOne({ name: "Manoj", email: "m@nextsem.online", role: "admin" })
db.users.insertMany([{name: "User1"}, {name: "User2"}])
// Read
db.users.find({role: "admin"}).pretty()
db.users.findOne({email: "m@nextsem.online"})
db.users.countDocuments({verified: true})
// Update
db.users.updateOne({email: "m@nextsem.online"}, {$set: {plan: "pro"}})
// Delete
db.users.deleteOne({email: "spam@test.com"})
`
Useful Queries:
```javascript
db.orders.find({total: {$gt: 1000}}) // Greater than
db.users.find({name: /^M/}) // Regex match
db.posts.find().sort({views: -1}).limit(5) // Top 5 by views
`
MongoDB is used by Uber, Facebook, Adobe — essential NoSQL knowledge! 🍃
