collection
Get access to the collection on the native mongodb driver
A connection index determines which database to connect with.
database
Get access to the database on the native mongodb driver
databaseInstance: Db
populateConfig: { field: string; model: MongoModel<any, any, any>; options?: PopulateOptions<any> & { unwind?: boolean; }; }
count(filter?: ,options?: AggregateOptions & { cache?: TCacheOptions; },)
Count all documents given a specific filter/conditions.
create(doc: InputDocument<InputShape>,options?: InsertOneOptions & { validate?: boolean; },): Promise<OutputDocument<OutputShape>>
Create a new document in the collection
createIndex(...indexDesc: (CreateIndexesOptions & { key: Partial<Record<string, IndexDirection>>; partialFilterExpression?: Filter<InputDocument<InputShape>>; })[])
Create a new index
createMany(docs: InputDocument<InputShape>[],options?: BulkWriteOptions & { validate?: boolean; },): Promise<OutputDocument<OutputShape>[]>
Create multiple documents in a single query
deleteMany(filter?: Filter<InputDocument<InputShape>>,options?: DeleteOptions,)
Delete many documents
deleteManyOrFail(filter?: Filter<InputDocument<InputShape>>,options?: DeleteOptions,)
Try to delete many documents. Throws an error if couldn't delete.
deleteOne(filter?: ,options?: DeleteOptions,)
Delete a single document
deleteOneOrFail(filter?: ,options?: DeleteOptions,)
Try to delete a single document. Throws an error if couldn't delete.
exists(filter?: ,options?: CountDocumentsOptions & { cache?: TCacheOptions; },)
Check if document(s) exists.
find(filter?: Filter<InputDocument<InputShape>>,options?: AggregateOptions & { cache?: TCacheOptions; },)
Find documents from this collection
findAndDeleteMany(filter?: Filter<InputDocument<InputShape>>,options?: DeleteOptions,)
Find many and delete them
findAndDeleteOne(filter?: ,options?: DeleteOptions,)
Find and delete a single document, returning the document.
findAndUpdateMany(filter?: Filter<InputDocument<InputShape>>,updates?: UpdateFilter<InputDocument<InputShape>> & Partial<InputDocument<InputShape>>,options?: UpdateOptions & { validate?: boolean; },)
Find many documents and update them, returning the old version of documents.
findAndUpdateOne(filter?: ,updates?: UpdateFilter<InputDocument<InputShape>> & Partial<InputDocument<InputShape>>,options?: UpdateOptions & { validate?: boolean; },)
Find a single document and update it. Returns the old verion of the document
findOne(filter?: ,options?: AggregateOptions & { cache?: TCacheOptions; },)
Find a single document
findOneOrFail(filter?: ,options?: AggregateOptions & { cache?: TCacheOptions; },)
Try to find a single document. If not found, throws an error.
Get the validator schema of this model.
Get the validator schema of this model in update state.
populate<M extends MongoModel<any, any, any>,S = OutputDocument<M extends MongoModel<any, any, infer R> ? R : never>,>(field: F,model: M,options?: PopulateOptions<M>,): MongoModel<Schema, InputShape, PopulatedDocument<OutputShape, F, S[]>>
Populates the array of references with documents referenced of another collection.
populateOne<M extends MongoModel<any, any, any>,S = OutputDocument<M extends MongoModel<any, any, infer R> ? R : never>,>(field: F,model: M,options?: PopulateOptions<M>,): MongoModel<Schema, InputShape, PopulatedDocument<OutputShape, F, S>>
Populate a reference with a document
replaceOne()
Replace a single document with another document
search()
Search for documents on this collection using full text index
A full text search index is required.
updateAndFindMany(filter?: Filter<InputDocument<InputShape>>,updates?: UpdateFilter<InputDocument<InputShape>> & Partial<InputDocument<InputShape>>,options?: UpdateOptions & { validate?: boolean; },)
Update many documents and then return them.
updateAndFindOne(filter?: ,updates?: UpdateFilter<InputDocument<InputShape>> & Partial<InputDocument<InputShape>>,options?: UpdateOptions & { validate?: boolean; },)
Update a single document and then return the updated document
updateMany(filter?: Filter<InputDocument<InputShape>>,updates?: UpdateFilter<InputDocument<InputShape>> & Partial<InputDocument<InputShape>>,options?: UpdateOptions & { validate?: boolean; },)
Update many documents
updateManyOrFail(filter?: Filter<InputDocument<InputShape>>,updates?: UpdateFilter<InputDocument<InputShape>> & Partial<InputDocument<InputShape>>,options?: UpdateOptions & { validate?: boolean; },)
Try to update many documents. Throws an error if failed or couldn't update a single document.
updateOne(filter?: ,updates?: UpdateFilter<InputDocument<InputShape>> & Partial<InputDocument<InputShape>>,options?: UpdateOptions & { validate?: boolean; },)
Update a single document
updateOneOrFail(filter?: ,updates?: UpdateFilter<InputDocument<InputShape>> & Partial<InputDocument<InputShape>>,options?: UpdateOptions & { validate?: boolean; },)
Try to update a single document. Throws an error if failed to update or condition didn't met.
watch(filter?: ,options?: ChangeStreamOptions,)
Watch for real time updates from mongodb