Does a dry-run of Model.syncIndexes(), meaning that the result of this function would be the result of Model.syncIndexes().
Sends createIndex
commands to mongo for each index declared in the schema.
The createIndex
commands are sent in series.
Lists the indexes currently defined in MongoDB. This may or may not be
the same as the indexes defined in your schema depending on whether you
use the autoIndex
option and if you
build indexes manually.
Makes the indexes in MongoDB match the indexes defined in this model's
schema. This function will drop any indexes that are not defined in
the model's schema except the _id
index, and build any indexes that
are in your schema but not in MongoDB.
Adds a discriminator type.
Sends multiple insertOne
, updateOne
, updateMany
, replaceOne
,
deleteOne
, and/or deleteMany
operations to the MongoDB server in one
command. This is faster than sending multiple independent operations (e.g.
if you use create()
) because with bulkWrite()
there is only one network
round trip to the MongoDB server.
Sends multiple save()
calls in a single bulkWrite()
. This is faster than
sending multiple save()
calls because with bulkSave()
there is only one
network round trip to the MongoDB server.
Creates a count
query: counts the number of documents that match filter
.
Creates a countDocuments
query: counts the number of documents that match filter
.
Creates a new document or documents
Create the collection for this model. By default, if no indexes are specified, mongoose will not create the collection for the model until any documents are created. Use this method to create the collection explicitly.
Deletes all of the documents that match conditions
from the collection.
Behaves like remove()
, but deletes all documents that match conditions
regardless of the single
option.
Deletes the first document that matches conditions
from the collection.
Behaves like remove()
, but deletes at most one document regardless of the
single
option.
Finds a single document by its _id field. findById(id)
is almost*
equivalent to findOne({ _id: id })
. If you want to query by a document's
_id
, use findById()
instead of findOne()
.
Finds one document.
Shortcut for creating a new Document from existing raw data, pre-saved in the DB. The document returned has no paths marked as modified initially.
This function is responsible for building indexes,
unless autoIndex
is turned off.
Mongoose calls this function automatically when a model is created using
mongoose.model()
or
connection.model()
, so you
don't need to call it.
Inserts one or more new documents as a single insertMany
call to the MongoDB server.
Populates document references.
Casts and validates the given object against this model's schema, passing the given context
to custom validators.
Watches the underlying collection for changes using MongoDB change streams.
Adds a $where
clause to this query
Translate any aliases fields/conditions so the final query or document object is pure
Creates a distinct
query: returns the distinct values of the given field
that match filter
.
Creates a estimatedDocumentCount
query: counts the number of documents in the collection.
Returns a document with its _id
if at least one document exists in the database that matches
the given filter
, and null
otherwise.
Creates a find
query: gets a list of documents that match filter
.
Creates a findByIdAndDelete
query, filtering by the given _id
.
Creates a findByIdAndRemove
query, filtering by the given _id
.
Creates a findOneAndUpdate
query, filtering by the given _id
.
Creates a findOneAndDelete
query: atomically finds the given document, deletes it, and returns the document as it was before deletion.
Creates a findOneAndRemove
query: atomically finds the given document and deletes it.
Creates a findOneAndReplace
query: atomically finds the given document and replaces it with replacement
.
Creates a findOneAndUpdate
query: atomically find the first document that matches filter
and apply update
.
Executes a mapReduce command.
Creates a replaceOne
query: finds the first document that matches filter
and replaces it with replacement
.
Creates a updateMany
query: updates all documents that match filter
with update
.
Creates a updateOne
query: updates the first document that matches filter
with update
.
Creates a Query, applies the passed conditions, and returns the Query.
Starts a MongoDB session for benefits like causal consistency, retryable writes, and transactions.
Base Mongoose instance the model uses.
If this is a discriminator model, baseModelName
is the name of
the base model.
Collection the model uses.
Connection the model uses.
Event emitter that reports any errors that occurred. Useful for global error handling.
The name of the model
Registered discriminators for this model.
Schema the model uses.
Generated using TypeDoc
Similar to
ensureIndexes()
, except for it uses thecreateIndex
function.