mongodb+srv://<username>:<password>@<cluster>/test
mongosh "mongodb+srv://<cluster>/myFirstDatabase" --apiVersion 1 --username mongo
mongosh "mongodb+srv://<username>:<password>@<cluster>/test" --apiVersion 1
mongosh "mongodb+srv://<username>:<password>@<cluster>/sample_airbnb" --apiVersion 1
mongodump --uri "mongodb+srv://<username>:<password>@<cluster>/sample_airbnb"
mongoexport --uri "mongodb+srv://<username>:<password>@<cluster>/sample_airbnb" --collection=listingsAndReviews --out=listingsAndReviews.json
show dbs
use <databasename>
show collections
db.<collectionName>.find({"<fieldName>":"<fieldValue>"})
db.<collectionName>.count()
db.<collectionName>.find({"<fieldName>":"<fieldValue>"}).pretty()
db.zips.insert({
city: 'HUEYTOWN',
zip: '35023',
loc: { y: 33.414625, x: 86.999607 },
pop: 39677,
state: 'AL'
});
db.zips.insert({
_id: Object("")
city: 'HUEYTOWN',
zip: '35023',
loc: { y: 33.414625, x: 86.999607 },
pop: 39677,
state: 'AL'
});
// insert multiple documents
db.zips.insert([{
_id: Object("")
city: 'HUEYTOWN',
zip: '35023',
loc: { y: 33.414625, x: 86.999607 },
pop: 39677,
state: 'AL'
}, {...}]);
// ordered
db.pets.insert([{ "_id": 1, "pet": "cat" },
{ "_id": 1, "pet": "dog" },
{ "_id": 3, "pet": "fish" },
{ "_id": 4, "pet": "snake" }], { "ordered": false })
// => cat, finish, snake documents will be inserted
MQL : MongoDB Query Language
// we can use this operator
db.zips.updateMany({"city":"HUDSON"},{"$set": {"area":9876.54}});
- Delete Document - db.{collectionName}.deleteOne({})/.deleteMany({})
- Delete Collection - db.{collectionName}.drop();
- Delete Database - drop