diff --git a/docs/api.html b/docs/api.html
index 0013ccea31..ef0d48f3f4 100644
--- a/docs/api.html
+++ b/docs/api.html
@@ -1,5 +1,5 @@
-Mongoose v8.7.3: Redirect to API
+Mongoose v8.8.0: Redirect to API
diff --git a/docs/api/aggregate.html b/docs/api/aggregate.html
index faddbf6e25..b83d2cabd7 100644
--- a/docs/api/aggregate.html
+++ b/docs/api/aggregate.html
@@ -1,4 +1,4 @@
-Mongoose v8.7.3: Aggregate
+Mongoose v8.8.0: Aggregate
Aggregate
+Mongoose v8.8.0: AggregationCursor
AggregationCursor
+Mongoose v8.8.0: Array
Array
+Mongoose v8.8.0: ArraySubdocument
ArraySubdocument
+Mongoose v8.8.0: Buffer
Buffer
+Mongoose v8.8.0: Connection
Connection
+Mongoose v8.8.0: Decimal128
Decimal128
+Mongoose v8.8.0: Document
Document
+Mongoose v8.8.0: DocumentArray
DocumentArray
+Mongoose v8.8.0: Error
Error
+Mongoose v8.8.0: Map
Map
+Mongoose v8.8.0: Model
Model
Model()
Model.$where()
Model.aggregate()
Model.applyDefaults()
Model.applyVirtuals()
Model.bulkSave()
Model.bulkWrite()
Model.castObject()
Model.cleanIndexes()
Model.countDocuments()
Model.create()
Model.createCollection()
Model.createIndexes()
Model.createSearchIndex()
Model.db
Model.deleteMany()
Model.deleteOne()
Model.diffIndexes()
Model.discriminator()
Model.distinct()
Model.dropSearchIndex()
Model.ensureIndexes()
Model.estimatedDocumentCount()
Model.events
Model.exists()
Model.find()
Model.findById()
Model.findByIdAndDelete()
Model.findByIdAndUpdate()
Model.findOne()
Model.findOneAndDelete()
Model.findOneAndReplace()
Model.findOneAndUpdate()
Model.hydrate()
Model.init()
Model.insertMany()
Model.inspect()
Model.listIndexes()
Model.listSearchIndexes()
Model.populate()
Model.prototype.$model()
Model.prototype.$where
Model.prototype.base
Model.prototype.baseModelName
Model.prototype.collection
Model.prototype.collection
Model.prototype.db
Model.prototype.deleteOne()
Model.prototype.discriminators
Model.prototype.increment()
Model.prototype.model()
Model.prototype.modelName
Model.prototype.save()
Model.recompileSchema()
Model.replaceOne()
Model.schema
Model.startSession()
Model.syncIndexes()
Model.translateAliases()
Model.updateMany()
Model.updateOne()
Model.updateSearchIndex()
Model.validate()
Model.watch()
Model.where()
Model()
Parameters:
doc
+})();Model()
Model.$where()
Model.aggregate()
Model.applyDefaults()
Model.applyTimestamps()
Model.applyVirtuals()
Model.bulkSave()
Model.bulkWrite()
Model.castObject()
Model.cleanIndexes()
Model.countDocuments()
Model.create()
Model.createCollection()
Model.createIndexes()
Model.createSearchIndex()
Model.db
Model.deleteMany()
Model.deleteOne()
Model.diffIndexes()
Model.discriminator()
Model.distinct()
Model.dropSearchIndex()
Model.ensureIndexes()
Model.estimatedDocumentCount()
Model.events
Model.exists()
Model.find()
Model.findById()
Model.findByIdAndDelete()
Model.findByIdAndUpdate()
Model.findOne()
Model.findOneAndDelete()
Model.findOneAndReplace()
Model.findOneAndUpdate()
Model.hydrate()
Model.init()
Model.insertMany()
Model.inspect()
Model.listIndexes()
Model.listSearchIndexes()
Model.populate()
Model.prototype.$model()
Model.prototype.$where
Model.prototype.base
Model.prototype.baseModelName
Model.prototype.collection
Model.prototype.collection
Model.prototype.db
Model.prototype.deleteOne()
Model.prototype.discriminators
Model.prototype.increment()
Model.prototype.model()
Model.prototype.modelName
Model.prototype.save()
Model.recompileSchema()
Model.replaceOne()
Model.schema
Model.startSession()
Model.syncIndexes()
Model.translateAliases()
Model.updateMany()
Model.updateOne()
Model.updateSearchIndex()
Model.validate()
Model.watch()
Model.where()
Model()
Parameters:
doc
«Object» values for initial set
[fields]
«Object» optional object containing the fields that were selected in the query which returned this document. You do not need to set this parameter to ensure Mongoose handles your query projection.
@@ -94,7 +94,26 @@
Model.applyDefaults()
Parameters:
obj
«Object|Document» object or document to apply defaults on
Apply defaults to the given document or POJO.
-
Model.applyVirtuals()
Parameters:
obj
+
Model.applyTimestamps()
Parameters:
obj
+«Object» object or document to apply virtuals on
+[options]
+«Object» [options.isUpdate=false]
+«Boolean» if true, treat this as an update: just set updatedAt, skip setting createdAt. If false, set both createdAt and updatedAt
+
[options.currentTime]
+«Function» if set, Mongoose will call this function to get the current time.
+
Apply this model's timestamps to a given POJO, including subdocument timestamps
+
+
+ Example:
+
+
+const userSchema = new Schema({ name: String }, { timestamps: true });
+const User = mongoose.model('User', userSchema);
+
+const obj = { name: 'John' };
+User.applyTimestamps(obj);
+obj.createdAt; // 2024-06-01T18:00:00.000Z
+obj.updatedAt; // 2024-06-01T18:00:00.000Z
Model.applyVirtuals()
Parameters:
obj
«Object» object or document to apply virtuals on
[virtualsToApply]
«Array<string>» optional whitelist of virtuals to apply
@@ -272,9 +291,12 @@
const obj = Test.castObject({ num: '42' });
obj.num; // 42 as a number
-Test.castObject({ num: 'not a number' }); // Throws a ValidationError
Model.cleanIndexes()
Parameters:
[callback]
-«Function» optional callback
-
Returns:
- «Promise,undefined,void» Returns
undefined
if callback is specified, returns a promise if no callback.
Deletes all indexes that aren't defined in this model's schema. Used by
+Test.castObject({ num: 'not a number' }); // Throws a ValidationError
Model.cleanIndexes()
Parameters:
[options]
+«Object» [options.toDrop]
+«Array<String>» if specified, contains a list of index names to drop
+
[options.hideIndexes=false]
+«Boolean» set to true
to hide indexes instead of dropping. Requires MongoDB server 4.4 or higher
+
Returns:
- «Promise<String>» list of dropped or hidden index names
Deletes all indexes that aren't defined in this model's schema. Used by
syncIndexes()
.
The returned promise resolves to a list of the dropped indexes' names as an array
Model.countDocuments()
Parameters:
filter
@@ -1192,6 +1214,8 @@
«Object» options to pass to ensureIndexes()
[options.background=null]
«Boolean» if specified, overrides each index's background
property
+
[options.hideIndexes=false]
+«Boolean» set to true
to hide indexes instead of dropping. Requires MongoDB server 4.4 or higher
Returns:
- «Promise»
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
diff --git a/docs/api/mongoose.html b/docs/api/mongoose.html
index 9c47aacfd3..5cf0194dbf 100644
--- a/docs/api/mongoose.html
+++ b/docs/api/mongoose.html
@@ -1,4 +1,4 @@
-
Mongoose v8.7.3: Mongoose
+Mongoose v8.8.0: Mongoose
Mongoose
+Mongoose v8.8.0: Query
Query
Query()
Query.prototype.$where()
Query.prototype.all()
Query.prototype.allowDiskUse()
Query.prototype.and()
Query.prototype.batchSize()
Query.prototype.box()
Query.prototype.cast()
Query.prototype.catch()
Query.prototype.center()
Query.prototype.centerSphere()
Query.prototype.circle()
Query.prototype.clone()
Query.prototype.collation()
Query.prototype.comment()
Query.prototype.countDocuments()
Query.prototype.cursor()
Query.prototype.deleteMany()
Query.prototype.deleteOne()
Query.prototype.distinct()
Query.prototype.elemMatch()
Query.prototype.equals()
Query.prototype.error()
Query.prototype.estimatedDocumentCount()
Query.prototype.exec()
Query.prototype.exists()
Query.prototype.explain()
Query.prototype.finally()
Query.prototype.find()
Query.prototype.findOne()
Query.prototype.findOneAndDelete()
Query.prototype.findOneAndReplace()
Query.prototype.findOneAndUpdate()
Query.prototype.geometry()
Query.prototype.get()
Query.prototype.getFilter()
Query.prototype.getOptions()
Query.prototype.getPopulatedPaths()
Query.prototype.getQuery()
Query.prototype.getUpdate()
Query.prototype.gt()
Query.prototype.gte()
Query.prototype.hint()
Query.prototype.in()
Query.prototype.intersects()
Query.prototype.isPathSelectedInclusive()
Query.prototype.j()
Query.prototype.lean()
Query.prototype.limit()
Query.prototype.lt()
Query.prototype.lte()
Query.prototype.maxDistance()
Query.prototype.maxTimeMS()
Query.prototype.merge()
Query.prototype.mod()
Query.prototype.model
Query.prototype.mongooseOptions()
Query.prototype.ne()
Query.prototype.near()
Query.prototype.nearSphere()
Query.prototype.nin()
Query.prototype.nor()
Query.prototype.or()
Query.prototype.orFail()
Query.prototype.polygon()
Query.prototype.populate()
Query.prototype.post()
Query.prototype.pre()
Query.prototype.projection()
Query.prototype.read()
Query.prototype.readConcern()
Query.prototype.regex()
Query.prototype.replaceOne()
Query.prototype.sanitizeProjection()
Query.prototype.select()
Query.prototype.selected()
Query.prototype.selectedExclusively()
Query.prototype.selectedInclusively()
Query.prototype.session()
Query.prototype.set()
Query.prototype.setOptions()
Query.prototype.setQuery()
Query.prototype.setUpdate()
Query.prototype.size()
Query.prototype.skip()
Query.prototype.slice()
Query.prototype.sort()
Query.prototype.tailable()
Query.prototype.then()
Query.prototype.toConstructor()
Query.prototype.transform()
Query.prototype.updateMany()
Query.prototype.updateOne()
Query.prototype.w()
Query.prototype.where()
Query.prototype.within()
Query.prototype.writeConcern()
Query.prototype.wtimeout()
Query.prototype[Symbol.asyncIterator]()
Query.prototype[Symbol.toStringTag]()
Query.use$geoWithin
Query()
Parameters:
[options]
+})();Query()
Query.prototype.$where()
Query.prototype.all()
Query.prototype.allowDiskUse()
Query.prototype.and()
Query.prototype.batchSize()
Query.prototype.box()
Query.prototype.cast()
Query.prototype.catch()
Query.prototype.center()
Query.prototype.centerSphere()
Query.prototype.circle()
Query.prototype.clone()
Query.prototype.collation()
Query.prototype.comment()
Query.prototype.countDocuments()
Query.prototype.cursor()
Query.prototype.deleteMany()
Query.prototype.deleteOne()
Query.prototype.distinct()
Query.prototype.elemMatch()
Query.prototype.equals()
Query.prototype.error()
Query.prototype.estimatedDocumentCount()
Query.prototype.exec()
Query.prototype.exists()
Query.prototype.explain()
Query.prototype.finally()
Query.prototype.find()
Query.prototype.findOne()
Query.prototype.findOneAndDelete()
Query.prototype.findOneAndReplace()
Query.prototype.findOneAndUpdate()
Query.prototype.geometry()
Query.prototype.get()
Query.prototype.getFilter()
Query.prototype.getOptions()
Query.prototype.getPopulatedPaths()
Query.prototype.getQuery()
Query.prototype.getUpdate()
Query.prototype.gt()
Query.prototype.gte()
Query.prototype.hint()
Query.prototype.in()
Query.prototype.intersects()
Query.prototype.isPathSelectedInclusive()
Query.prototype.j()
Query.prototype.lean()
Query.prototype.limit()
Query.prototype.lt()
Query.prototype.lte()
Query.prototype.maxDistance()
Query.prototype.maxTimeMS()
Query.prototype.merge()
Query.prototype.mod()
Query.prototype.model
Query.prototype.mongooseOptions()
Query.prototype.ne()
Query.prototype.near()
Query.prototype.nearSphere()
Query.prototype.nin()
Query.prototype.nor()
Query.prototype.or()
Query.prototype.orFail()
Query.prototype.polygon()
Query.prototype.populate()
Query.prototype.post()
Query.prototype.pre()
Query.prototype.projection()
Query.prototype.read()
Query.prototype.readConcern()
Query.prototype.regex()
Query.prototype.replaceOne()
Query.prototype.sanitizeProjection()
Query.prototype.schemaLevelProjections()
Query.prototype.select()
Query.prototype.selected()
Query.prototype.selectedExclusively()
Query.prototype.selectedInclusively()
Query.prototype.session()
Query.prototype.set()
Query.prototype.setOptions()
Query.prototype.setQuery()
Query.prototype.setUpdate()
Query.prototype.size()
Query.prototype.skip()
Query.prototype.slice()
Query.prototype.sort()
Query.prototype.tailable()
Query.prototype.then()
Query.prototype.toConstructor()
Query.prototype.transform()
Query.prototype.updateMany()
Query.prototype.updateOne()
Query.prototype.w()
Query.prototype.where()
Query.prototype.within()
Query.prototype.writeConcern()
Query.prototype.wtimeout()
Query.prototype[Symbol.asyncIterator]()
Query.prototype[Symbol.toStringTag]()
Query.use$geoWithin
Query()
Parameters:
[options]
«Object» [model]
«Object» [conditions]
«Object» [collection]
@@ -902,6 +902,7 @@
strict
: controls how Mongoose handles keys that aren't in the schema for updates. This option is true
by default, which means Mongoose will silently strip any paths in the update that aren't in the schema. See the strict
mode docs for more information.
strictQuery
: controls how Mongoose handles keys that aren't in the schema for the query filter
. This option is false
by default, which means Mongoose will allow Model.find({ foo: 'bar' })
even if foo
is not in the schema. See the strictQuery
docs for more information.
nearSphere
: use $nearSphere
instead of near()
. See the Query.prototype.nearSphere()
docs
+schemaLevelProjections
: if false
, Mongoose will not apply schema-level select: false
or select: true
for this query
Mongoose maintains a separate object for internal options because
Mongoose sends Query.prototype.options
to the MongoDB server, and the
@@ -1249,7 +1250,24 @@
// With `sanitizeProjection`, Mongoose prevents projecting in `password` and other
// fields that have `select: false` in the schema.
doc = await UserModel.findOne().sanitizeProjection(true).select('+password');
-doc.password; // undefined
Query.prototype.select()
Parameters:
arg
+doc.password; // undefined
Query.prototype.schemaLevelProjections()
Parameters:
value
+«Boolean»
Returns:
- «Query» this
See:
Enable or disable schema level projections for this query. Enabled by default.
+Set to false
to include fields with select: false
in the query result by default.
+
+
+ Example:
+
+
+const userSchema = new Schema({
+ email: { type: String, required: true },
+ passwordHash: { type: String, select: false, required: true }
+});
+const UserModel = mongoose.model('User', userSchema);
+
+const doc = await UserModel.findOne().orFail().schemaLevelProjections(false);
+
+// Contains password hash, because `schemaLevelProjections()` overrides `select: false`
+doc.passwordHash;
Query.prototype.select()
Parameters:
arg
«Object|String|Array[String]»
Returns:
- «Query» this
See:
Specifies which document fields to include or exclude (also known as the query "projection")
When using string syntax, prefixing a path with -
will flag that path as excluded. When a path does not have the -
prefix, it is included. Lastly, if a path is prefixed with +
, it forces inclusion of the path, which is useful for paths excluded at the schema level.
A projection must be either inclusive or exclusive. In other words, you must
diff --git a/docs/api/querycursor.html b/docs/api/querycursor.html
index dc7df5e35f..f9d65d5189 100644
--- a/docs/api/querycursor.html
+++ b/docs/api/querycursor.html
@@ -1,4 +1,4 @@
-
Mongoose v8.7.3: QueryCursor
+Mongoose v8.8.0: QueryCursor
QueryCursor
+Mongoose v8.8.0: Schema
Schema
+Mongoose v8.8.0: SchemaArray
SchemaArray
+Mongoose v8.8.0: SchemaArrayOptions
SchemaArrayOptions
+Mongoose v8.8.0: SchemaBoolean
SchemaBoolean
+Mongoose v8.8.0: SchemaBuffer
SchemaBuffer
+Mongoose v8.8.0: SchemaBufferOptions
SchemaBufferOptions
+Mongoose v8.8.0: SchemaDateOptions
diff --git a/docs/api/aggregate.html b/docs/api/aggregate.html
index faddbf6e25..b83d2cabd7 100644
--- a/docs/api/aggregate.html
+++ b/docs/api/aggregate.html
@@ -1,4 +1,4 @@
-Mongoose v8.7.3: Aggregate
+Mongoose v8.8.0: Aggregate
Aggregate
+Mongoose v8.8.0: AggregationCursor
AggregationCursor
+Mongoose v8.8.0: Array
Array
+Mongoose v8.8.0: ArraySubdocument
ArraySubdocument
+Mongoose v8.8.0: Buffer
Buffer
+Mongoose v8.8.0: Connection
Connection
+Mongoose v8.8.0: Decimal128
Decimal128
+Mongoose v8.8.0: Document
Document
+Mongoose v8.8.0: DocumentArray
DocumentArray
+Mongoose v8.8.0: Error
Error
+Mongoose v8.8.0: Map
Map
+Mongoose v8.8.0: Model
Model
Model()
Model.$where()
Model.aggregate()
Model.applyDefaults()
Model.applyVirtuals()
Model.bulkSave()
Model.bulkWrite()
Model.castObject()
Model.cleanIndexes()
Model.countDocuments()
Model.create()
Model.createCollection()
Model.createIndexes()
Model.createSearchIndex()
Model.db
Model.deleteMany()
Model.deleteOne()
Model.diffIndexes()
Model.discriminator()
Model.distinct()
Model.dropSearchIndex()
Model.ensureIndexes()
Model.estimatedDocumentCount()
Model.events
Model.exists()
Model.find()
Model.findById()
Model.findByIdAndDelete()
Model.findByIdAndUpdate()
Model.findOne()
Model.findOneAndDelete()
Model.findOneAndReplace()
Model.findOneAndUpdate()
Model.hydrate()
Model.init()
Model.insertMany()
Model.inspect()
Model.listIndexes()
Model.listSearchIndexes()
Model.populate()
Model.prototype.$model()
Model.prototype.$where
Model.prototype.base
Model.prototype.baseModelName
Model.prototype.collection
Model.prototype.collection
Model.prototype.db
Model.prototype.deleteOne()
Model.prototype.discriminators
Model.prototype.increment()
Model.prototype.model()
Model.prototype.modelName
Model.prototype.save()
Model.recompileSchema()
Model.replaceOne()
Model.schema
Model.startSession()
Model.syncIndexes()
Model.translateAliases()
Model.updateMany()
Model.updateOne()
Model.updateSearchIndex()
Model.validate()
Model.watch()
Model.where()
Model()
Parameters:
doc
+})();Model()
Model.$where()
Model.aggregate()
Model.applyDefaults()
Model.applyTimestamps()
Model.applyVirtuals()
Model.bulkSave()
Model.bulkWrite()
Model.castObject()
Model.cleanIndexes()
Model.countDocuments()
Model.create()
Model.createCollection()
Model.createIndexes()
Model.createSearchIndex()
Model.db
Model.deleteMany()
Model.deleteOne()
Model.diffIndexes()
Model.discriminator()
Model.distinct()
Model.dropSearchIndex()
Model.ensureIndexes()
Model.estimatedDocumentCount()
Model.events
Model.exists()
Model.find()
Model.findById()
Model.findByIdAndDelete()
Model.findByIdAndUpdate()
Model.findOne()
Model.findOneAndDelete()
Model.findOneAndReplace()
Model.findOneAndUpdate()
Model.hydrate()
Model.init()
Model.insertMany()
Model.inspect()
Model.listIndexes()
Model.listSearchIndexes()
Model.populate()
Model.prototype.$model()
Model.prototype.$where
Model.prototype.base
Model.prototype.baseModelName
Model.prototype.collection
Model.prototype.collection
Model.prototype.db
Model.prototype.deleteOne()
Model.prototype.discriminators
Model.prototype.increment()
Model.prototype.model()
Model.prototype.modelName
Model.prototype.save()
Model.recompileSchema()
Model.replaceOne()
Model.schema
Model.startSession()
Model.syncIndexes()
Model.translateAliases()
Model.updateMany()
Model.updateOne()
Model.updateSearchIndex()
Model.validate()
Model.watch()
Model.where()
Model()
Parameters:
doc
«Object» values for initial set
[fields]
«Object» optional object containing the fields that were selected in the query which returned this document. You do not need to set this parameter to ensure Mongoose handles your query projection.
@@ -94,7 +94,26 @@
Model.applyDefaults()
Parameters:
obj
«Object|Document» object or document to apply defaults on
Apply defaults to the given document or POJO.
-
Model.applyVirtuals()
Parameters:
obj
+
Model.applyTimestamps()
Parameters:
obj
+«Object» object or document to apply virtuals on
+[options]
+«Object» [options.isUpdate=false]
+«Boolean» if true, treat this as an update: just set updatedAt, skip setting createdAt. If false, set both createdAt and updatedAt
+
[options.currentTime]
+«Function» if set, Mongoose will call this function to get the current time.
+
Apply this model's timestamps to a given POJO, including subdocument timestamps
+
+
+ Example:
+
+
+const userSchema = new Schema({ name: String }, { timestamps: true });
+const User = mongoose.model('User', userSchema);
+
+const obj = { name: 'John' };
+User.applyTimestamps(obj);
+obj.createdAt; // 2024-06-01T18:00:00.000Z
+obj.updatedAt; // 2024-06-01T18:00:00.000Z
Model.applyVirtuals()
Parameters:
obj
«Object» object or document to apply virtuals on
[virtualsToApply]
«Array<string>» optional whitelist of virtuals to apply
@@ -272,9 +291,12 @@
const obj = Test.castObject({ num: '42' });
obj.num; // 42 as a number
-Test.castObject({ num: 'not a number' }); // Throws a ValidationError
Model.cleanIndexes()
Parameters:
[callback]
-«Function» optional callback
-
Returns:
- «Promise,undefined,void» Returns
undefined
if callback is specified, returns a promise if no callback.
Deletes all indexes that aren't defined in this model's schema. Used by
+Test.castObject({ num: 'not a number' }); // Throws a ValidationError
Model.cleanIndexes()
Parameters:
[options]
+«Object» [options.toDrop]
+«Array<String>» if specified, contains a list of index names to drop
+
[options.hideIndexes=false]
+«Boolean» set to true
to hide indexes instead of dropping. Requires MongoDB server 4.4 or higher
+
Returns:
- «Promise<String>» list of dropped or hidden index names
Deletes all indexes that aren't defined in this model's schema. Used by
syncIndexes()
.
The returned promise resolves to a list of the dropped indexes' names as an array
Model.countDocuments()
Parameters:
filter
@@ -1192,6 +1214,8 @@
«Object» options to pass to ensureIndexes()
[options.background=null]
«Boolean» if specified, overrides each index's background
property
+
[options.hideIndexes=false]
+«Boolean» set to true
to hide indexes instead of dropping. Requires MongoDB server 4.4 or higher
Returns:
- «Promise»
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
diff --git a/docs/api/mongoose.html b/docs/api/mongoose.html
index 9c47aacfd3..5cf0194dbf 100644
--- a/docs/api/mongoose.html
+++ b/docs/api/mongoose.html
@@ -1,4 +1,4 @@
-
Mongoose v8.7.3: Mongoose
+Mongoose v8.8.0: Mongoose
Mongoose
+Mongoose v8.8.0: Query
Query
Query()
Query.prototype.$where()
Query.prototype.all()
Query.prototype.allowDiskUse()
Query.prototype.and()
Query.prototype.batchSize()
Query.prototype.box()
Query.prototype.cast()
Query.prototype.catch()
Query.prototype.center()
Query.prototype.centerSphere()
Query.prototype.circle()
Query.prototype.clone()
Query.prototype.collation()
Query.prototype.comment()
Query.prototype.countDocuments()
Query.prototype.cursor()
Query.prototype.deleteMany()
Query.prototype.deleteOne()
Query.prototype.distinct()
Query.prototype.elemMatch()
Query.prototype.equals()
Query.prototype.error()
Query.prototype.estimatedDocumentCount()
Query.prototype.exec()
Query.prototype.exists()
Query.prototype.explain()
Query.prototype.finally()
Query.prototype.find()
Query.prototype.findOne()
Query.prototype.findOneAndDelete()
Query.prototype.findOneAndReplace()
Query.prototype.findOneAndUpdate()
Query.prototype.geometry()
Query.prototype.get()
Query.prototype.getFilter()
Query.prototype.getOptions()
Query.prototype.getPopulatedPaths()
Query.prototype.getQuery()
Query.prototype.getUpdate()
Query.prototype.gt()
Query.prototype.gte()
Query.prototype.hint()
Query.prototype.in()
Query.prototype.intersects()
Query.prototype.isPathSelectedInclusive()
Query.prototype.j()
Query.prototype.lean()
Query.prototype.limit()
Query.prototype.lt()
Query.prototype.lte()
Query.prototype.maxDistance()
Query.prototype.maxTimeMS()
Query.prototype.merge()
Query.prototype.mod()
Query.prototype.model
Query.prototype.mongooseOptions()
Query.prototype.ne()
Query.prototype.near()
Query.prototype.nearSphere()
Query.prototype.nin()
Query.prototype.nor()
Query.prototype.or()
Query.prototype.orFail()
Query.prototype.polygon()
Query.prototype.populate()
Query.prototype.post()
Query.prototype.pre()
Query.prototype.projection()
Query.prototype.read()
Query.prototype.readConcern()
Query.prototype.regex()
Query.prototype.replaceOne()
Query.prototype.sanitizeProjection()
Query.prototype.select()
Query.prototype.selected()
Query.prototype.selectedExclusively()
Query.prototype.selectedInclusively()
Query.prototype.session()
Query.prototype.set()
Query.prototype.setOptions()
Query.prototype.setQuery()
Query.prototype.setUpdate()
Query.prototype.size()
Query.prototype.skip()
Query.prototype.slice()
Query.prototype.sort()
Query.prototype.tailable()
Query.prototype.then()
Query.prototype.toConstructor()
Query.prototype.transform()
Query.prototype.updateMany()
Query.prototype.updateOne()
Query.prototype.w()
Query.prototype.where()
Query.prototype.within()
Query.prototype.writeConcern()
Query.prototype.wtimeout()
Query.prototype[Symbol.asyncIterator]()
Query.prototype[Symbol.toStringTag]()
Query.use$geoWithin
Query()
Parameters:
[options]
+})();Query()
Query.prototype.$where()
Query.prototype.all()
Query.prototype.allowDiskUse()
Query.prototype.and()
Query.prototype.batchSize()
Query.prototype.box()
Query.prototype.cast()
Query.prototype.catch()
Query.prototype.center()
Query.prototype.centerSphere()
Query.prototype.circle()
Query.prototype.clone()
Query.prototype.collation()
Query.prototype.comment()
Query.prototype.countDocuments()
Query.prototype.cursor()
Query.prototype.deleteMany()
Query.prototype.deleteOne()
Query.prototype.distinct()
Query.prototype.elemMatch()
Query.prototype.equals()
Query.prototype.error()
Query.prototype.estimatedDocumentCount()
Query.prototype.exec()
Query.prototype.exists()
Query.prototype.explain()
Query.prototype.finally()
Query.prototype.find()
Query.prototype.findOne()
Query.prototype.findOneAndDelete()
Query.prototype.findOneAndReplace()
Query.prototype.findOneAndUpdate()
Query.prototype.geometry()
Query.prototype.get()
Query.prototype.getFilter()
Query.prototype.getOptions()
Query.prototype.getPopulatedPaths()
Query.prototype.getQuery()
Query.prototype.getUpdate()
Query.prototype.gt()
Query.prototype.gte()
Query.prototype.hint()
Query.prototype.in()
Query.prototype.intersects()
Query.prototype.isPathSelectedInclusive()
Query.prototype.j()
Query.prototype.lean()
Query.prototype.limit()
Query.prototype.lt()
Query.prototype.lte()
Query.prototype.maxDistance()
Query.prototype.maxTimeMS()
Query.prototype.merge()
Query.prototype.mod()
Query.prototype.model
Query.prototype.mongooseOptions()
Query.prototype.ne()
Query.prototype.near()
Query.prototype.nearSphere()
Query.prototype.nin()
Query.prototype.nor()
Query.prototype.or()
Query.prototype.orFail()
Query.prototype.polygon()
Query.prototype.populate()
Query.prototype.post()
Query.prototype.pre()
Query.prototype.projection()
Query.prototype.read()
Query.prototype.readConcern()
Query.prototype.regex()
Query.prototype.replaceOne()
Query.prototype.sanitizeProjection()
Query.prototype.schemaLevelProjections()
Query.prototype.select()
Query.prototype.selected()
Query.prototype.selectedExclusively()
Query.prototype.selectedInclusively()
Query.prototype.session()
Query.prototype.set()
Query.prototype.setOptions()
Query.prototype.setQuery()
Query.prototype.setUpdate()
Query.prototype.size()
Query.prototype.skip()
Query.prototype.slice()
Query.prototype.sort()
Query.prototype.tailable()
Query.prototype.then()
Query.prototype.toConstructor()
Query.prototype.transform()
Query.prototype.updateMany()
Query.prototype.updateOne()
Query.prototype.w()
Query.prototype.where()
Query.prototype.within()
Query.prototype.writeConcern()
Query.prototype.wtimeout()
Query.prototype[Symbol.asyncIterator]()
Query.prototype[Symbol.toStringTag]()
Query.use$geoWithin
Query()
Parameters:
[options]
«Object» [model]
«Object» [conditions]
«Object» [collection]
@@ -902,6 +902,7 @@
strict
: controls how Mongoose handles keys that aren't in the schema for updates. This option is true
by default, which means Mongoose will silently strip any paths in the update that aren't in the schema. See the strict
mode docs for more information.
strictQuery
: controls how Mongoose handles keys that aren't in the schema for the query filter
. This option is false
by default, which means Mongoose will allow Model.find({ foo: 'bar' })
even if foo
is not in the schema. See the strictQuery
docs for more information.
nearSphere
: use $nearSphere
instead of near()
. See the Query.prototype.nearSphere()
docs
+schemaLevelProjections
: if false
, Mongoose will not apply schema-level select: false
or select: true
for this query
Mongoose maintains a separate object for internal options because
Mongoose sends Query.prototype.options
to the MongoDB server, and the
@@ -1249,7 +1250,24 @@
// With `sanitizeProjection`, Mongoose prevents projecting in `password` and other
// fields that have `select: false` in the schema.
doc = await UserModel.findOne().sanitizeProjection(true).select('+password');
-doc.password; // undefined
Query.prototype.select()
Parameters:
arg
+doc.password; // undefined
Query.prototype.schemaLevelProjections()
Parameters:
value
+«Boolean»
Returns:
- «Query» this
See:
Enable or disable schema level projections for this query. Enabled by default.
+Set to false
to include fields with select: false
in the query result by default.
+
+
+ Example:
+
+
+const userSchema = new Schema({
+ email: { type: String, required: true },
+ passwordHash: { type: String, select: false, required: true }
+});
+const UserModel = mongoose.model('User', userSchema);
+
+const doc = await UserModel.findOne().orFail().schemaLevelProjections(false);
+
+// Contains password hash, because `schemaLevelProjections()` overrides `select: false`
+doc.passwordHash;
Query.prototype.select()
Parameters:
arg
«Object|String|Array[String]»
Returns:
- «Query» this
See:
Specifies which document fields to include or exclude (also known as the query "projection")
When using string syntax, prefixing a path with -
will flag that path as excluded. When a path does not have the -
prefix, it is included. Lastly, if a path is prefixed with +
, it forces inclusion of the path, which is useful for paths excluded at the schema level.
A projection must be either inclusive or exclusive. In other words, you must
diff --git a/docs/api/querycursor.html b/docs/api/querycursor.html
index dc7df5e35f..f9d65d5189 100644
--- a/docs/api/querycursor.html
+++ b/docs/api/querycursor.html
@@ -1,4 +1,4 @@
-
Mongoose v8.7.3: QueryCursor
+Mongoose v8.8.0: QueryCursor
QueryCursor
+Mongoose v8.8.0: Schema
Schema
+Mongoose v8.8.0: SchemaArray
SchemaArray
+Mongoose v8.8.0: SchemaArrayOptions
SchemaArrayOptions
+Mongoose v8.8.0: SchemaBoolean
SchemaBoolean
+Mongoose v8.8.0: SchemaBuffer
SchemaBuffer
+Mongoose v8.8.0: SchemaBufferOptions
SchemaBufferOptions
+Mongoose v8.8.0: SchemaDateOptions
Aggregate
AggregationCursor
Array
ArraySubdocument
Buffer
Connection
Decimal128
Document
DocumentArray
Error
Map
Model
Model()
Model.$where()
Model.aggregate()
Model.applyDefaults()
Model.applyVirtuals()
Model.bulkSave()
Model.bulkWrite()
Model.castObject()
Model.cleanIndexes()
Model.countDocuments()
Model.create()
Model.createCollection()
Model.createIndexes()
Model.createSearchIndex()
Model.db
Model.deleteMany()
Model.deleteOne()
Model.diffIndexes()
Model.discriminator()
Model.distinct()
Model.dropSearchIndex()
Model.ensureIndexes()
Model.estimatedDocumentCount()
Model.events
Model.exists()
Model.find()
Model.findById()
Model.findByIdAndDelete()
Model.findByIdAndUpdate()
Model.findOne()
Model.findOneAndDelete()
Model.findOneAndReplace()
Model.findOneAndUpdate()
Model.hydrate()
Model.init()
Model.insertMany()
Model.inspect()
Model.listIndexes()
Model.listSearchIndexes()
Model.populate()
Model.prototype.$model()
Model.prototype.$where
Model.prototype.base
Model.prototype.baseModelName
Model.prototype.collection
Model.prototype.collection
Model.prototype.db
Model.prototype.deleteOne()
Model.prototype.discriminators
Model.prototype.increment()
Model.prototype.model()
Model.prototype.modelName
Model.prototype.save()
Model.recompileSchema()
Model.replaceOne()
Model.schema
Model.startSession()
Model.syncIndexes()
Model.translateAliases()
Model.updateMany()
Model.updateOne()
Model.updateSearchIndex()
Model.validate()
Model.watch()
Model.where()
Model()
Parameters:
doc
+})();Model()
Model.$where()
Model.aggregate()
Model.applyDefaults()
Model.applyTimestamps()
Model.applyVirtuals()
Model.bulkSave()
Model.bulkWrite()
Model.castObject()
Model.cleanIndexes()
Model.countDocuments()
Model.create()
Model.createCollection()
Model.createIndexes()
Model.createSearchIndex()
Model.db
Model.deleteMany()
Model.deleteOne()
Model.diffIndexes()
Model.discriminator()
Model.distinct()
Model.dropSearchIndex()
Model.ensureIndexes()
Model.estimatedDocumentCount()
Model.events
Model.exists()
Model.find()
Model.findById()
Model.findByIdAndDelete()
Model.findByIdAndUpdate()
Model.findOne()
Model.findOneAndDelete()
Model.findOneAndReplace()
Model.findOneAndUpdate()
Model.hydrate()
Model.init()
Model.insertMany()
Model.inspect()
Model.listIndexes()
Model.listSearchIndexes()
Model.populate()
Model.prototype.$model()
Model.prototype.$where
Model.prototype.base
Model.prototype.baseModelName
Model.prototype.collection
Model.prototype.collection
Model.prototype.db
Model.prototype.deleteOne()
Model.prototype.discriminators
Model.prototype.increment()
Model.prototype.model()
Model.prototype.modelName
Model.prototype.save()
Model.recompileSchema()
Model.replaceOne()
Model.schema
Model.startSession()
Model.syncIndexes()
Model.translateAliases()
Model.updateMany()
Model.updateOne()
Model.updateSearchIndex()
Model.validate()
Model.watch()
Model.where()
Model()
Parameters:
doc
«Object» values for initial set[fields]
«Object» optional object containing the fields that were selected in the query which returned this document. You do not need to set this parameter to ensure Mongoose handles your query projection. @@ -94,7 +94,26 @@
Model.applyDefaults()
Parameters:
obj
«Object|Document» object or document to apply defaults on
Apply defaults to the given document or POJO.
-Model.applyVirtuals()
Parameters:
obj
+
Model.applyTimestamps()
Parameters:
obj
+«Object» object or document to apply virtuals on +[options]
+«Object»[options.isUpdate=false]
+«Boolean» if true, treat this as an update: just set updatedAt, skip setting createdAt. If false, set both createdAt and updatedAt +[options.currentTime]
+«Function» if set, Mongoose will call this function to get the current time. +
Apply this model's timestamps to a given POJO, including subdocument timestamps
++ + Example: + +
+const userSchema = new Schema({ name: String }, { timestamps: true });
+const User = mongoose.model('User', userSchema);
+
+const obj = { name: 'John' };
+User.applyTimestamps(obj);
+obj.createdAt; // 2024-06-01T18:00:00.000Z
+obj.updatedAt; // 2024-06-01T18:00:00.000Z
Model.applyVirtuals()
Parameters:
obj
«Object» object or document to apply virtuals on[virtualsToApply]
«Array<string>» optional whitelist of virtuals to apply @@ -272,9 +291,12 @@const obj = Test.castObject({ num: '42' }); obj.num; // 42 as a number -Test.castObject({ num: 'not a number' }); // Throws a ValidationError
Model.cleanIndexes()
Parameters:
[callback]
-«Function» optional callback -
Returns:
- «Promise,undefined,void» Returns
undefined
if callback is specified, returns a promise if no callback.
Deletes all indexes that aren't defined in this model's schema. Used by +Test.castObject({ num: 'not a number' }); // Throws a ValidationError
Model.cleanIndexes()
Parameters:
[options]
+«Object»[options.toDrop]
+«Array<String>» if specified, contains a list of index names to drop +[options.hideIndexes=false]
+«Boolean» set totrue
to hide indexes instead of dropping. Requires MongoDB server 4.4 or higher +
Returns:
- «Promise<String>» list of dropped or hidden index names
Deletes all indexes that aren't defined in this model's schema. Used by
syncIndexes()
.
The returned promise resolves to a list of the dropped indexes' names as an array
Model.countDocuments()
Parameters:
filter
@@ -1192,6 +1214,8 @@«Object» options to pass to
ensureIndexes()
[options.background=null]
«Boolean» if specified, overrides each index'sbackground
property +[options.hideIndexes=false]
+«Boolean» set totrue
to hide indexes instead of dropping. Requires MongoDB server 4.4 or higher
Returns:
- «Promise»
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
diff --git a/docs/api/mongoose.html b/docs/api/mongoose.html
index 9c47aacfd3..5cf0194dbf 100644
--- a/docs/api/mongoose.html
+++ b/docs/api/mongoose.html
@@ -1,4 +1,4 @@
-
Mongoose
Query
Query()
Query.prototype.$where()
Query.prototype.all()
Query.prototype.allowDiskUse()
Query.prototype.and()
Query.prototype.batchSize()
Query.prototype.box()
Query.prototype.cast()
Query.prototype.catch()
Query.prototype.center()
Query.prototype.centerSphere()
Query.prototype.circle()
Query.prototype.clone()
Query.prototype.collation()
Query.prototype.comment()
Query.prototype.countDocuments()
Query.prototype.cursor()
Query.prototype.deleteMany()
Query.prototype.deleteOne()
Query.prototype.distinct()
Query.prototype.elemMatch()
Query.prototype.equals()
Query.prototype.error()
Query.prototype.estimatedDocumentCount()
Query.prototype.exec()
Query.prototype.exists()
Query.prototype.explain()
Query.prototype.finally()
Query.prototype.find()
Query.prototype.findOne()
Query.prototype.findOneAndDelete()
Query.prototype.findOneAndReplace()
Query.prototype.findOneAndUpdate()
Query.prototype.geometry()
Query.prototype.get()
Query.prototype.getFilter()
Query.prototype.getOptions()
Query.prototype.getPopulatedPaths()
Query.prototype.getQuery()
Query.prototype.getUpdate()
Query.prototype.gt()
Query.prototype.gte()
Query.prototype.hint()
Query.prototype.in()
Query.prototype.intersects()
Query.prototype.isPathSelectedInclusive()
Query.prototype.j()
Query.prototype.lean()
Query.prototype.limit()
Query.prototype.lt()
Query.prototype.lte()
Query.prototype.maxDistance()
Query.prototype.maxTimeMS()
Query.prototype.merge()
Query.prototype.mod()
Query.prototype.model
Query.prototype.mongooseOptions()
Query.prototype.ne()
Query.prototype.near()
Query.prototype.nearSphere()
Query.prototype.nin()
Query.prototype.nor()
Query.prototype.or()
Query.prototype.orFail()
Query.prototype.polygon()
Query.prototype.populate()
Query.prototype.post()
Query.prototype.pre()
Query.prototype.projection()
Query.prototype.read()
Query.prototype.readConcern()
Query.prototype.regex()
Query.prototype.replaceOne()
Query.prototype.sanitizeProjection()
Query.prototype.select()
Query.prototype.selected()
Query.prototype.selectedExclusively()
Query.prototype.selectedInclusively()
Query.prototype.session()
Query.prototype.set()
Query.prototype.setOptions()
Query.prototype.setQuery()
Query.prototype.setUpdate()
Query.prototype.size()
Query.prototype.skip()
Query.prototype.slice()
Query.prototype.sort()
Query.prototype.tailable()
Query.prototype.then()
Query.prototype.toConstructor()
Query.prototype.transform()
Query.prototype.updateMany()
Query.prototype.updateOne()
Query.prototype.w()
Query.prototype.where()
Query.prototype.within()
Query.prototype.writeConcern()
Query.prototype.wtimeout()
Query.prototype[Symbol.asyncIterator]()
Query.prototype[Symbol.toStringTag]()
Query.use$geoWithin
Query()
Parameters:
[options]
+})();Query()
Query.prototype.$where()
Query.prototype.all()
Query.prototype.allowDiskUse()
Query.prototype.and()
Query.prototype.batchSize()
Query.prototype.box()
Query.prototype.cast()
Query.prototype.catch()
Query.prototype.center()
Query.prototype.centerSphere()
Query.prototype.circle()
Query.prototype.clone()
Query.prototype.collation()
Query.prototype.comment()
Query.prototype.countDocuments()
Query.prototype.cursor()
Query.prototype.deleteMany()
Query.prototype.deleteOne()
Query.prototype.distinct()
Query.prototype.elemMatch()
Query.prototype.equals()
Query.prototype.error()
Query.prototype.estimatedDocumentCount()
Query.prototype.exec()
Query.prototype.exists()
Query.prototype.explain()
Query.prototype.finally()
Query.prototype.find()
Query.prototype.findOne()
Query.prototype.findOneAndDelete()
Query.prototype.findOneAndReplace()
Query.prototype.findOneAndUpdate()
Query.prototype.geometry()
Query.prototype.get()
Query.prototype.getFilter()
Query.prototype.getOptions()
Query.prototype.getPopulatedPaths()
Query.prototype.getQuery()
Query.prototype.getUpdate()
Query.prototype.gt()
Query.prototype.gte()
Query.prototype.hint()
Query.prototype.in()
Query.prototype.intersects()
Query.prototype.isPathSelectedInclusive()
Query.prototype.j()
Query.prototype.lean()
Query.prototype.limit()
Query.prototype.lt()
Query.prototype.lte()
Query.prototype.maxDistance()
Query.prototype.maxTimeMS()
Query.prototype.merge()
Query.prototype.mod()
Query.prototype.model
Query.prototype.mongooseOptions()
Query.prototype.ne()
Query.prototype.near()
Query.prototype.nearSphere()
Query.prototype.nin()
Query.prototype.nor()
Query.prototype.or()
Query.prototype.orFail()
Query.prototype.polygon()
Query.prototype.populate()
Query.prototype.post()
Query.prototype.pre()
Query.prototype.projection()
Query.prototype.read()
Query.prototype.readConcern()
Query.prototype.regex()
Query.prototype.replaceOne()
Query.prototype.sanitizeProjection()
Query.prototype.schemaLevelProjections()
Query.prototype.select()
Query.prototype.selected()
Query.prototype.selectedExclusively()
Query.prototype.selectedInclusively()
Query.prototype.session()
Query.prototype.set()
Query.prototype.setOptions()
Query.prototype.setQuery()
Query.prototype.setUpdate()
Query.prototype.size()
Query.prototype.skip()
Query.prototype.slice()
Query.prototype.sort()
Query.prototype.tailable()
Query.prototype.then()
Query.prototype.toConstructor()
Query.prototype.transform()
Query.prototype.updateMany()
Query.prototype.updateOne()
Query.prototype.w()
Query.prototype.where()
Query.prototype.within()
Query.prototype.writeConcern()
Query.prototype.wtimeout()
Query.prototype[Symbol.asyncIterator]()
Query.prototype[Symbol.toStringTag]()
Query.use$geoWithin
Query()
Parameters:
[options]
«Object»[model]
«Object»[conditions]
«Object»[collection]
@@ -902,6 +902,7 @@strict
: controls how Mongoose handles keys that aren't in the schema for updates. This option istrue
by default, which means Mongoose will silently strip any paths in the update that aren't in the schema. See thestrict
mode docs for more information.strictQuery
: controls how Mongoose handles keys that aren't in the schema for the queryfilter
. This option isfalse
by default, which means Mongoose will allowModel.find({ foo: 'bar' })
even iffoo
is not in the schema. See thestrictQuery
docs for more information.nearSphere
: use$nearSphere
instead ofnear()
. See theQuery.prototype.nearSphere()
docs
+schemaLevelProjections
: iffalse
, Mongoose will not apply schema-levelselect: false
orselect: true
for this query
Mongoose maintains a separate object for internal options because Mongoose sends
Query.prototype.options
to the MongoDB server, and the @@ -1249,7 +1250,24 @@// With `sanitizeProjection`, Mongoose prevents projecting in `password` and other // fields that have `select: false` in the schema. doc = await UserModel.findOne().sanitizeProjection(true).select('+password'); -doc.password; // undefined
Query.prototype.select()
Parameters:
arg
+doc.password; // undefined
Query.prototype.schemaLevelProjections()
Parameters:
value
+«Boolean»
Returns:
- «Query» this
See:
Enable or disable schema level projections for this query. Enabled by default.
+Set to false
to include fields with select: false
in the query result by default.
+ + Example: + +
+const userSchema = new Schema({
+ email: { type: String, required: true },
+ passwordHash: { type: String, select: false, required: true }
+});
+const UserModel = mongoose.model('User', userSchema);
+
+const doc = await UserModel.findOne().orFail().schemaLevelProjections(false);
+
+// Contains password hash, because `schemaLevelProjections()` overrides `select: false`
+doc.passwordHash;
Query.prototype.select()
Parameters:
arg
«Object|String|Array[String]»
Returns:
- «Query» this
See:
Specifies which document fields to include or exclude (also known as the query "projection")
When using string syntax, prefixing a path with -
will flag that path as excluded. When a path does not have the -
prefix, it is included. Lastly, if a path is prefixed with +
, it forces inclusion of the path, which is useful for paths excluded at the schema level.
A projection must be either inclusive or exclusive. In other words, you must diff --git a/docs/api/querycursor.html b/docs/api/querycursor.html index dc7df5e35f..f9d65d5189 100644 --- a/docs/api/querycursor.html +++ b/docs/api/querycursor.html @@ -1,4 +1,4 @@ -