MongoDB Collection Methods

MongoDB provides a set of methods for managing collections, allowing you to perform operations such as creating, deleting, renaming, and listing collections. This page summarizes the collection methods available in MongoDB.

  1. aggregate

    The MongoDB aggregate() method can be used to perform aggregation operations on a MongoDB collection and supports SQL-like aggregation operations such as group, sort, project, etc.
  2. bulkWrite

    The bulkWrite() method in MongoDB is an API for performing batch operations that support multiple types of operations such as inserts, updates, and deletes in a single request.
  3. count

    The count() method is an aggregation function in MongoDB used to count the number of documents that meet specified conditions.
  4. countDocuments

    The MongoDB countDocuments() method is a commonly used query method that can be used to count the number of documents that meet certain criteria.
  5. createIndex

    The MongoDB createIndex() method is used to create an index.
  6. createIndexes

    The createIndexes() method in MongoDB is used to create one or more indexes in a collection.
  7. dataSize

    dataSize() is a method in MongoDB used to return the size of all documents in a collection or index in bytes.
  8. deleteMany

    The deleteMany() method is a method for deleting multiple documents in MongoDB.
  9. deleteOne

    The MongoDB deleteOne() method is mainly used to delete a single document in a collection
  10. distinct

    The distinct() method is a method in MongoDB used to obtain the unique values of a specified field in a collection.
  11. drop

    In MongoDB, the drop() method is used to delete a specified collection.
  12. dropIndex

    The MongoDB dropIndex() method is used to remove an index.
  13. dropIndexes

    The dropIndexes() method is a MongoDB method used to delete one or more indexes in a collection.
  14. ensureIndex

    The ensureIndex() method is a method in MongoDB used to create indexes.
  15. estimatedDocumentCount

    In MongoDB, the estimatedDocumentCount() method is used to estimate the number of documents in a collection, which can improve query performance when dealing with large datasets.
  16. explain

    The MongoDB explain() method analyzes detailed information about query execution, including the indexes used, the number of documents scanned, and more.
  17. find

    find() is one of the most commonly used methods in MongoDB for retrieving documents from a collection.
  18. findAndModify

    findAndModify() is a collection operation method in MongoDB that allows users to return the document before the update when performing an update operation.
  19. findOne

    The findOne() method is a query method in MongoDB database used to query a single document in a collection that matches the specified criteria and return that document.
  20. findOneAndDelete

    In MongoDB, findOneAndDelete() is a method used to find and delete a single document.
  21. findOneAndReplace

    The findOneAndReplace() method in MongoDB is used to find the first document in a collection that matches a given condition and replaces it with a new document.
  22. findOneAndUpdate

    The MongoDB findOneAndUpdate() method can find and modify or update a document based on the query condition.
  23. getIndexes

    The getIndexes() method is a built-in method of MongoDB that can return all index information in a collection.
  24. getShardDistribution

    getShardDistribution() is a method in MongoDB used to query the distribution of a sharded collection.
  25. getShardVersion

    The getShardVersion() method is a method in MongoDB used to retrieve shard version information.
  26. hideIndex

    The MongoDB hideIndex() method is used to hide a specific index in a specified collection.
  27. insertMany

    The insertMany() method in MongoDB is used to insert multiple new documents into a MongoDB database.
  28. insertOne

    The insertOne() method in MongoDB is used to insert a single new document into a database.
  29. Introduction to MongoDB collection.insert() Method

    The insert() method in MongoDB is used to insert a new document into a MongoDB database.
  30. Introduction to MongoDB collection.update() Method

    In MongoDB, the update() method is used to modify data in one or more documents.
  31. isCapped

    The isCapped() method is a built-in method in MongoDB used to check if a collection is a capped collection.
  32. latencyStats

    latencyStats() is a method in MongoDB that returns latency statistics for operations during a specified time period.
  33. mapReduce

    The mapReduce() method in MongoDB is a powerful data processing tool that can perform custom aggregation and processing on data in a collection.
  34. reIndex

    The reIndex() method is a method in MongoDB used to rebuild indexes.
  35. remove

    The MongoDB remove() method is used to remove documents from a MongoDB database.
  36. renameCollection

    renameCollection() is a collection management method in MongoDB that can be used to rename a collection.
  37. replaceOne

    replaceOne() is an update operation in MongoDB that replaces a document that matches a specified filter.
  38. stats

    stats() is a method in MongoDB that can be used to retrieve statistics information about a collection.
  39. storageSize

    storageSize() is a method in MongoDB that can be used to retrieve the storage size of a collection.
  40. totalIndexSize

    totalIndexSize() is a method in MongoDB that can be used to get the total size of all indexes in a collection.
  41. totalSize

    totalSize() is a method in MongoDB that can be used to get the total size of a collection.
  42. unhideIndex

    unhideIndex() is a method in MongoDB used to hide specified indexes in the database.
  43. updateMany

    The updateMany() method method can be used to update data in multiple documents at the same time.
  44. updateOne

    The updateOne() method is one of the methods in MongoDB used to update a single document.
  45. validate

    The validate() method is used in MongoDB to check if a collection is valid.
  46. watch

    The watch() method in MongoDB can monitor data changes in a collection and return corresponding change streams.