Common collection operations in MongoDB include:
-
Insert Operations:
insertOne(document): Inserts a single document into a collection.insertMany(documents): Inserts multiple documents into a collection.
-
Query Operations:
find(query): Retrieves documents that match the specified query criteria. Returns a cursor to the matching documents.findOne(query): Retrieves a single document that matches the query criteria.
-
Update Operations:
updateOne(filter, update): Updates a single document that matches the filter criteria.updateMany(filter, update): Updates multiple documents that match the filter criteria.replaceOne(filter, replacement): Replaces a single document that matches the filter criteria with a new document.
-
Delete Operations:
deleteOne(filter): Deletes a single document that matches the filter criteria.deleteMany(filter): Deletes multiple documents that match the filter criteria.
-
Aggregation Operations:
aggregate(pipeline): Performs aggregation operations on the documents in a collection, allowing for complex data processing and analysis.
-
Indexing Operations:
createIndex(indexSpecification): Creates an index on a collection to improve query performance.dropIndex(indexName): Removes an index from a collection.
These operations allow for effective management and manipulation of data within MongoDB collections, enabling users to perform CRUD (Create, Read, Update, Delete) operations and more advanced data processing tasks.
