---
type: link
tags: [public]
created: 2025-10-27T09:17:57.483Z
---# mongoDB commands list

**URL:** [https://chatgpt.com/c/67309662-8158-8009-acd1-4f5d5cce7033](https://chatgpt.com/c/67309662-8158-8009-acd1-4f5d5cce7033)

mongoDB commands list Basic Database and Collection Commands show dbs Lists all databases. use Switches to the specified database, creating it if it doesn’t exist. db Shows the current database. show collections Lists all collections in the current database. db.createCollection(" ") Creates a new collection in the current database. db.dropDatabase() Deletes the current database. Query/Find Operators db.collection.find({ category: { $in: ["x", "y", "z"] } }) returns records in categories either in x,y or z db.collection.find({ category: { $nin: ["x", "y", "z"] } }) returns records in other than categories x,y or z db.collection.find({ category: { $all: ["x", "y", "z"] } }) returns records that are included in all categories; x,y and z CRUD Operations db.collection.insertOne({}) Inserts a single document into a collection. db.collection.insertMany([{}, {}]) Inserts multiple documents into a collection. db.collection.find() Retrieves all documents from a collection. db.collection.findOne({}) Finds the first document that matches the specified query. db.collection.updateOne({}, { $set: {} }) Updates a single document that matches the query. db.collection.updateMany({}, { $set: {} }) Updates multiple documents that match the query. db.collection.deleteOne({}) Deletes a single document that matches the query. db.collection.deleteMany({}) Deletes all documents that match the query. Query Modifiers db.collection.find().limit( ) Limits the number of documents returned. db.collection.find().sort({ : 1 }) Sorts documents by the specified field. Use 1 for ascending and -1 for descending. db.collection.find().skip( ) Skips a specified number of documents in the result. db.collection.countDocuments({}) Counts the number of documents that match the query. Index and Aggregation Commands db.collection.createIndex({ : 1 }) Creates an index on a specified field. db.collection.aggregate([ { $match: {} }, { $group: {} } ]) Runs an aggregation pipeline on a collection for complex data processing.


---
**Keywords:** public
