0% found this document useful (0 votes)
47 views1 page

MongoDB Basic Commands

This document provides a list of basic MongoDB commands categorized by their actions, such as starting the shell, managing databases and collections, inserting, querying, updating, and deleting documents. Each command is presented in a concise format for easy reference. It serves as a quick guide for users to perform essential MongoDB operations.

Uploaded by

Sreemita Dey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views1 page

MongoDB Basic Commands

This document provides a list of basic MongoDB commands categorized by their actions, such as starting the shell, managing databases and collections, inserting, querying, updating, and deleting documents. Each command is presented in a concise format for easy reference. It serves as a quick guide for users to perform essential MongoDB operations.

Uploaded by

Sreemita Dey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Basic MongoDB Commands

Category Action Command

Start MongoDB Shell Start MongoDB mongo

Database Show databases show dbs

Database Use/select a database use myDatabase

Database Show current database db

Database Drop/delete database db.dropDatabase()

Collection Show collections show collections

Collection Create collection db.createCollection("myCollection")

Collection Drop collection db.myCollection.drop()

Insert Insert one document db.myCollection.insertOne({ name: "Alice", age: 25 })

Insert Insert many documents db.myCollection.insertMany([{ name: "Bob" }, { name: "Carol"

Query Find all documents db.myCollection.find()

Query Find with condition db.myCollection.find({ age: 25 })

Query Find one document db.myCollection.findOne({ name: "Alice" })

Query Pretty print db.myCollection.find().pretty()

Update Update one db.myCollection.updateOne({ name: "Alice" }, { $set: { age: 2

Update Update many db.myCollection.updateMany({ age: 25 }, { $set: { status: "ac

Update Replace document db.myCollection.replaceOne({ name: "Bob" }, { name: "Bobby

Delete Delete one db.myCollection.deleteOne({ name: "Carol" })

Delete Delete many db.myCollection.deleteMany({ age: 25 })

Other Count documents db.myCollection.countDocuments()

Other Limit results db.myCollection.find().limit(5)

Other Sort results db.myCollection.find().sort({ age: 1 })

You might also like