The MongoDB adapter provides a service interface for MongoDB databases using the official MongoDB Node.js driver.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/feathersjs/feathers/llms.txt
Use this file to discover all available pages before exploring further.
Installation
MongoDBService
The main service class for MongoDB operations.Constructor
Configuration options for the MongoDB adapter
MongoDB collection instance or a promise that resolves to one
Name of the id field property
Pagination settings with
default and max page sizeAllow multiple updates. Can be
true, false, or an array of method names like ['create', 'patch', 'remove']If
true, disables automatic ObjectId conversion for the id fieldIf
true, uses MongoDB’s estimatedDocumentCount instead of countDocuments for better performanceService Methods
find
Retrieve multiple documents from the collection.Returns paginated results or an array depending on pagination settings
get
Retrieve a single document by id.The document id to retrieve
Query parameters
The found document
create
Create one or more new documents.Document data to create. Can be a single object or array of objects
MongoDB-specific insert options
The created document(s)
update
Completely replace a document.The document id to update
Complete document data to replace with
The updated document
patch
Partially update one or multiple documents.The document id to patch, or
null to patch multiple documentsPartial data to merge with existing document(s). Supports MongoDB update operators like
$set, $inc, etc.The patched document(s)
remove
Remove one or multiple documents.The document id to remove, or
null to remove multiple documentsThe removed document(s)
MongoDbAdapter
The base adapter class thatMongoDBService extends. Provides internal methods prefixed with _ that bypass hooks.
Methods
getObjectId
Converts an id value to an ObjectId if appropriate.The id value to convert
The converted id (ObjectId if applicable)
getModel
Retrieve the MongoDB collection instance.The MongoDB collection
aggregateRaw
Execute a MongoDB aggregation pipeline.Aggregation pipeline stages. Use
{ $feathers: true } as a stage marker to inject Feathers query filtersMongoDB aggregation cursor
findRaw
Execute a MongoDB find query without processing results.MongoDB find cursor
Query Syntax
The MongoDB adapter supports Feathers query syntax and MongoDB-specific operators.Standard Query Operators
Special Query Parameters
Aggregation Pipeline
Use thepipeline parameter for complex aggregations:
MongoDB Update Operators in patch
ObjectId Converters
Utility functions for working with MongoDB ObjectIds in schemas.resolveObjectId
Convert a string, number, or ObjectId to ObjectId.resolveQueryObjectId
Convert ObjectId query parameters including$in, $nin, $ne.