Installation
MongoDBService
The main service class for MongoDB operations.Constructor
MongoDBAdapterOptions
required
Configuration options for the MongoDB adapter
Collection | Promise<Collection>
required
MongoDB collection instance or a promise that resolves to one
string
default:"_id"
Name of the id field property
PaginationParams
Pagination settings with
default and max page sizeboolean | string[]
Allow multiple updates. Can be
true, false, or an array of method names like ['create', 'patch', 'remove']boolean
If
true, disables automatic ObjectId conversion for the id fieldboolean
If
true, uses MongoDB’s estimatedDocumentCount instead of countDocuments for better performanceService Methods
find
Retrieve multiple documents from the collection.MongoDBAdapterParams
Paginated<Result> | Result[]
Returns paginated results or an array depending on pagination settings
get
Retrieve a single document by id.Id | ObjectId
required
The document id to retrieve
MongoDBAdapterParams
Query parameters
Result
The found document
create
Create one or more new documents.Data | Data[]
required
Document data to create. Can be a single object or array of objects
Result | Result[]
The created document(s)
update
Completely replace a document.Id | ObjectId
required
The document id to update
Data
required
Complete document data to replace with
Result
The updated document
patch
Partially update one or multiple documents.Id | ObjectId | null
required
The document id to patch, or
null to patch multiple documentsPatchData
required
Partial data to merge with existing document(s). Supports MongoDB update operators like
$set, $inc, etc.MongoDBAdapterParams
Result | Result[]
The patched document(s)
remove
Remove one or multiple documents.Id | ObjectId | null
required
The document id to remove, or
null to remove multiple documentsMongoDBAdapterParams
Result | Result[]
The 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.Id | ObjectId
required
The id value to convert
Id | ObjectId
The converted id (ObjectId if applicable)
getModel
Retrieve the MongoDB collection instance.Collection
The MongoDB collection
aggregateRaw
Execute a MongoDB aggregation pipeline.MongoDBAdapterParams
required
Document[]
Aggregation pipeline stages. Use
{ $feathers: true } as a stage marker to inject Feathers query filtersAggregationCursor
MongoDB aggregation cursor
findRaw
Execute a MongoDB find query without processing results.FindCursor
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.