MQL

MongoDB

  • Data is stored in documents

  • Documents are stored in Collections

  • Document here refers to JSON

  • Redundant copies of data are stored in replica set

  • JSON is stored as BSON internally in MongoDB

# FOR BSON, use dump (backup) and restore (restore backup)

mongodump --uri "mongodb+srv://<your username>:<your password>@<your cluster>.mongodb.net/<database name>"

# drop will delete the stuff already in and create the new object from restore

mongorestore --uri "mongodb+srv://<your username>:<your password>@<your cluster>.mongodb.net/<database name>"  --drop dump

# FOR JSON, use export (backup) and import (import backup)

# collection to specify which collection
# out to specify the file name to export to

mongoexport --uri="mongodb+srv://<your username>:<your password>@<your cluster>.mongodb.net/<database name>" --collection=sales --out=sales.json

mongoimport --uri="mongodb+srv://<your username>:<your password>@<your cluster>.mongodb.net/<database name>" --drop sales.json

Queries

Find

  • Each Document has a unique object _id which is set by default if not specfied

Insert

Insert conflicts

Updates

https://docs.mongodb.com/manual/reference/operator/update/#id1

Upsert

Delete

Operators

  • AND operator is present in your qureies when not specified

EXPR

Array

Array operators and Projection

  • Elematch : matches documents that contains an array field with at least one element that matches the specified query creteria

  • Elematch : Projects only the array elements with at least one element that matches the specified criteria

Array Operators and Sub-Documents

Sort and Limit

  • Use sort before limit always

Last updated

Was this helpful?