This cheat sheet provides a concise summary of basic MongoDB commands and operations. It outlines commands for connecting to and switching between databases, viewing and creating collections, and inserting, finding, updating, replacing, and deleting documents. It also summarizes common query operators like $eq, $gt, $lt, and $in for filtering documents based on field values. Functions like .count() and .sort() are mentioned for counting and sorting query results.
This cheat sheet provides a concise summary of basic MongoDB commands and operations. It outlines commands for connecting to and switching between databases, viewing and creating collections, and inserting, finding, updating, replacing, and deleting documents. It also summarizes common query operators like $eq, $gt, $lt, and $in for filtering documents based on field values. Functions like .count() and .sort() are mentioned for counting and sorting query results.
This cheat sheet provides a concise summary of basic MongoDB commands and operations. It outlines commands for connecting to and switching between databases, viewing and creating collections, and inserting, finding, updating, replacing, and deleting documents. It also summarizes common query operators like $eq, $gt, $lt, and $in for filtering documents based on field values. Functions like .count() and .sort() are mentioned for counting and sorting query results.
This cheat sheet provides a concise summary of basic MongoDB commands and operations. It outlines commands for connecting to and switching between databases, viewing and creating collections, and inserting, finding, updating, replacing, and deleting documents. It also summarizes common query operators like $eq, $gt, $lt, and $in for filtering documents based on field values. Functions like .count() and .sort() are mentioned for counting and sorting query results.
db Show name of current database {key: Matches all documents containing subdoc‐
mongod Start database {$exists: ument key
true}} mongo Connect to database $eq Matches values that are equal to a specified show dbs Show databases value. use db Switch to database db $gt Matches values that are greater than a show collections Display current database collections specified value. $gte Matches values that are greater than or equal Create to a specified value. insert(data) insert document(s) $in Matches any of the values specified in an array returns write result syntax: {key:{$in: [array of values] } } insertOne (data, options) insert one document $lt Matches values that are less than a specified insertMany(data, options) insert many documents value. insertMany([{},{},{}]) needs square brackets $lte Matches values that are less than or equal to a specified value. Read $ne Matches all values that are not equal to a db.collectio‐ Display documents from specified value. n.find() collection $nin Matches none of the values specified in an find(filter, options) find all matching documents array.
findOne(filter, find first matching document $and Performs AND operation
options) syntax: {$and: [ {},{} ] }
{key: {$op: $and operator is necessary when the same field
Update filter}, or operator has to be specified in multiple updateOne(filter, data, Change one document {filter}} expressions options) find({‐ Filter sub documents updateMany(filter, data, Change many doc.subdo‐ options) documents c:value}) replaceOne(filter, data, Replace document options) entirely Functions