Mongodb Commands Cheat Sheet



DescriptionCommand
Show All Databasesshow dbs
Show Current Databasedb
Create Or Switch Databaseuse acme
Dropdb.dropDatabase()
Create Collectiondb.createCollection('posts')
Show Collectionsshow collections
Get All Rowsdb.posts.find()
Get All Rows Formatteddb.find().pretty()
Find Rowsdb.posts.find({ category: 'News' })
Sort Rowsasc: db.posts.find().sort({ title: 1 }).pretty()
desc: db.posts.find().sort({ title: -1 }).pretty()
Count Rowsdb.posts.find().count()
db.posts.find({ category: 'news' }).count()
Limit Rowsdb.posts.find().limit(2).pretty()
Chainingdb.posts.find().limit(2).sort({ title: 1 }).pretty()
Foreachdb.posts.find().forEach(function(doc) {
print('Blog Post: ' + doc.title)})
Find One Rowdb.posts.findOne({ category: 'News' })
Find Specific Fieldsdb.posts.find({ title: 'Post One' }, {
title: 1,
author: 1})
Delete Rowdb.posts.remove({ title: 'Post Four' })
Add Indexdb.posts.createIndex({ title: 'text' })

Containers Cheat Sheet. Introduction to Container architecture. Engine, image, registry, volume, related commands. Example of running a web server container. MongoDB Cheat Sheet. MongoDB Commands Cheat Sheet for Beginners By Ajitesh Kumar on July 6, 2018 MongoDB, NoSQL In this post, you will learn about MongoDB commands which could get you started and perform minimum database related activities such as create, update, drop a collection (table). The above mongo command only works if your MongoDB server runs on the default port, which is 27017. If your MongoDB server runs on a different port, you have to explicitly specify it in the command, as shown below: mongo -port 28010 Remote server. Both of the above commands only work if your MongoDB server is running on the localhost. MongoDB Commands Listing (Administrative Command Helpers): The sections above provide helpful commands that can get you online on MongoDB and do some administrative tasks on MongoDB. This section specifically works upon the administrative tasks on databases created within the MongoDB database server.

Insert Row¶

Insert Multiple Rows¶

Update Row¶

Update Specific Field¶

Increment Field ($inc)¶

Mongo shell commandsMongodb Commands Cheat Sheet

Rename Field¶

Sub-Documents¶

Find By Element in Array ($elemMatch)¶

Commands

Text Search¶

Greater & Less Than¶

-->

APPLIES TO: SQL API

The Azure Cosmos DB query cheat sheets help you quickly write queries for your data by displaying common database queries, operations, functions, and operators in easy-to-print PDF reference sheets. The cheat sheets include reference information for the SQL, MongoDB, Table, and Gremlin APIs.

Choose from a letter-sized or A3-sized download.

Pymongo Cheat Sheet

Letter-sized cheat sheets

Mongodb Command Shell

Download the Azure Cosmos DB letter-sized query cheat sheets if you're going to print to letter-sized paper (8.5' x 11').

Oversized cheat sheets

Mongodb Commands Cheat Sheet Examples

Download the Azure Cosmos DB A3-sized query cheat sheets if you're going to print using a plotter or large-scale printer on A3-sized paper (11.7' x 16.5').

Next steps

For more help writing queries, see the following articles:

  • For SQL API queries, see Query using the SQL API, SQL queries for Azure Cosmos DB, and SQL syntax reference
  • For MongoDB queries, see Query using Azure Cosmos DB's API for MongoDB and Azure Cosmos DB's API for MongoDB feature support and syntax
  • For Gremlin API queries, see Query using the Gremlin API and Azure Cosmos DB Gremlin graph support
  • For Table API queries, see Query using the Table API