mongoose 6.11.0 → 6.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,16 +2,20 @@
2
2
 
3
3
  const utils = require('../utils');
4
4
 
5
- if (typeof jest !== 'undefined' && typeof window !== 'undefined') {
6
- utils.warn('Mongoose: looks like you\'re trying to test a Mongoose app ' +
7
- 'with Jest\'s default jsdom test environment. Please make sure you read ' +
8
- 'Mongoose\'s docs on configuring Jest to test Node.js apps: ' +
9
- 'https://mongoosejs.com/docs/jest.html');
10
- }
5
+ if (typeof jest !== 'undefined' && !process.env.SUPPRESS_JEST_WARNINGS) {
6
+ if (typeof window !== 'undefined') {
7
+ utils.warn('Mongoose: looks like you\'re trying to test a Mongoose app ' +
8
+ 'with Jest\'s default jsdom test environment. Please make sure you read ' +
9
+ 'Mongoose\'s docs on configuring Jest to test Node.js apps: ' +
10
+ 'https://mongoosejs.com/docs/jest.html. Set the SUPPRESS_JEST_WARNINGS to true ' +
11
+ 'to hide this warning.');
12
+ }
11
13
 
12
- if (typeof jest !== 'undefined' && setTimeout.clock != null && typeof setTimeout.clock.Date === 'function') {
13
- utils.warn('Mongoose: looks like you\'re trying to test a Mongoose app ' +
14
- 'with Jest\'s mock timers enabled. Please make sure you read ' +
15
- 'Mongoose\'s docs on configuring Jest to test Node.js apps: ' +
16
- 'https://mongoosejs.com/docs/jest.html');
14
+ if (setTimeout.clock != null && typeof setTimeout.clock.Date === 'function') {
15
+ utils.warn('Mongoose: looks like you\'re trying to test a Mongoose app ' +
16
+ 'with Jest\'s mock timers enabled. Please make sure you read ' +
17
+ 'Mongoose\'s docs on configuring Jest to test Node.js apps: ' +
18
+ 'https://mongoosejs.com/docs/jest.html. Set the SUPPRESS_JEST_WARNINGS to true ' +
19
+ 'to hide this warning.');
20
+ }
17
21
  }
package/lib/query.js CHANGED
@@ -2003,9 +2003,13 @@ Query.prototype._optionsForExec = function(model) {
2003
2003
  }
2004
2004
  }
2005
2005
 
2006
- const projection = this._fieldsForExec();
2007
- if (projection != null) {
2008
- options.projection = projection;
2006
+ this._applyPaths();
2007
+ if (this._fields != null) {
2008
+ this._fields = this._castFields(this._fields);
2009
+ const projection = this._fieldsForExec();
2010
+ if (projection != null) {
2011
+ options.projection = projection;
2012
+ }
2009
2013
  }
2010
2014
 
2011
2015
  return options;
@@ -2258,10 +2262,6 @@ Query.prototype._find = wrapThunk(function(callback) {
2258
2262
 
2259
2263
  callback = _wrapThunkCallback(this, callback);
2260
2264
 
2261
- this._applyPaths();
2262
- this._fields = this._castFields(this._fields);
2263
-
2264
- const fields = this._fieldsForExec();
2265
2265
  const mongooseOptions = this._mongooseOptions;
2266
2266
  const _this = this;
2267
2267
  const userProvidedFields = _this._userProvidedFields || {};
@@ -2276,6 +2276,10 @@ Query.prototype._find = wrapThunk(function(callback) {
2276
2276
  lean: mongooseOptions.lean || null
2277
2277
  });
2278
2278
 
2279
+ const options = this._optionsForExec();
2280
+ const filter = this._conditions;
2281
+ const fields = options.projection;
2282
+
2279
2283
  const cb = (err, docs) => {
2280
2284
  if (err) {
2281
2285
  return callback(err);
@@ -2317,8 +2321,6 @@ Query.prototype._find = wrapThunk(function(callback) {
2317
2321
  });
2318
2322
  };
2319
2323
 
2320
- const options = this._optionsForExec();
2321
- const filter = this._conditions;
2322
2324
 
2323
2325
  this._collection.collection.find(filter, options, (err, cursor) => {
2324
2326
  if (err != null) {
@@ -2531,8 +2533,6 @@ Query.prototype._findOne = wrapThunk(function(callback) {
2531
2533
  return null;
2532
2534
  }
2533
2535
 
2534
- this._applyPaths();
2535
- this._fields = this._castFields(this._fields);
2536
2536
  applyGlobalMaxTimeMS(this.options, this.model);
2537
2537
  applyGlobalDiskUse(this.options, this.model);
2538
2538
 
@@ -3852,17 +3852,6 @@ Query.prototype._findOneAndReplace = wrapThunk(function(callback) {
3852
3852
  const filter = this._conditions;
3853
3853
  const options = this._optionsForExec();
3854
3854
  convertNewToReturnDocument(options);
3855
- let fields = null;
3856
-
3857
- this._applyPaths();
3858
- if (this._fields != null) {
3859
- options.projection = this._castFields(utils.clone(this._fields));
3860
- fields = options.projection;
3861
- if (fields instanceof Error) {
3862
- callback(fields);
3863
- return null;
3864
- }
3865
- }
3866
3855
 
3867
3856
  const runValidators = _getOption(this, 'runValidators', false);
3868
3857
  if (runValidators === false) {
@@ -3991,7 +3980,6 @@ Query.prototype._findAndModify = function(type, callback) {
3991
3980
  const model = this.model;
3992
3981
  const schema = model.schema;
3993
3982
  const _this = this;
3994
- let fields;
3995
3983
 
3996
3984
  const castedQuery = castQuery(this);
3997
3985
  if (castedQuery instanceof Error) {
@@ -4062,18 +4050,6 @@ Query.prototype._findAndModify = function(type, callback) {
4062
4050
  }
4063
4051
  }
4064
4052
 
4065
- this._applyPaths();
4066
- if (this._fields) {
4067
- this._fields = this._castFields(this._fields);
4068
- fields = this._fieldsForExec();
4069
- if (fields != null) {
4070
- opts.projection = fields;
4071
- }
4072
- if (opts.projection instanceof Error) {
4073
- return callback(opts.projection);
4074
- }
4075
- }
4076
-
4077
4053
  if (opts.sort) convertSortToArray(opts);
4078
4054
 
4079
4055
  const cb = function(err, doc, res) {
@@ -5442,6 +5418,9 @@ Query.prototype._castFields = function _castFields(fields) {
5442
5418
  */
5443
5419
 
5444
5420
  Query.prototype._applyPaths = function applyPaths() {
5421
+ if (!this.model) {
5422
+ return;
5423
+ }
5445
5424
  this._fields = this._fields || {};
5446
5425
  helpers.applyPaths(this._fields, this.model.schema);
5447
5426
 
@@ -5500,9 +5479,6 @@ Query.prototype._applyPaths = function applyPaths() {
5500
5479
  */
5501
5480
 
5502
5481
  Query.prototype.cursor = function cursor(opts) {
5503
- this._applyPaths();
5504
- this._fields = this._castFields(this._fields);
5505
-
5506
5482
  if (opts) {
5507
5483
  this.setOptions(opts);
5508
5484
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "6.11.0",
4
+ "version": "6.11.1",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -80,6 +80,7 @@
80
80
  "docs:clean:6x": "rimraf index.html && rimraf -rf ./docs/6.x && rimraf -rf ./docs/source/_docs && rimraf -rf ./tmp",
81
81
  "docs:copy:tmp": "mkdirp ./tmp/docs/css && mkdirp ./tmp/docs/js && mkdirp ./tmp/docs/images && mkdirp ./tmp/docs/tutorials && mkdirp ./tmp/docs/typescript && mkdirp ./tmp/docs/api && ncp ./docs/css ./tmp/docs/css --filter=.css$ && ncp ./docs/js ./tmp/docs/js --filter=.js$ && ncp ./docs/images ./tmp/docs/images && ncp ./docs/tutorials ./tmp/docs/tutorials && ncp ./docs/typescript ./tmp/docs/typescript && ncp ./docs/api ./tmp/docs/api && cp index.html ./tmp && cp docs/*.html ./tmp/docs/",
82
82
  "docs:copy:tmp:5x": "rimraf ./docs/5.x && ncp ./tmp ./docs/5.x",
83
+ "docs:move:6x:tmp": "mv ./docs/6.x ./tmp",
83
84
  "docs:copy:tmp:6x": "rimraf ./docs/6.x && ncp ./tmp ./docs/6.x",
84
85
  "docs:checkout:gh-pages": "git checkout gh-pages",
85
86
  "docs:checkout:5x": "git checkout 5.x",
@@ -94,7 +95,7 @@
94
95
  "docs:view": "node ./scripts/static.js",
95
96
  "docs:prepare:publish:stable": "npm run docs:checkout:gh-pages && npm run docs:merge:stable && npm run docs:clean:stable && npm run docs:generate && npm run docs:generate:search",
96
97
  "docs:prepare:publish:5x": "npm run docs:checkout:5x && npm run docs:merge:5x && npm run docs:clean:stable && npm run docs:generate && npm run docs:copy:tmp && npm run docs:checkout:gh-pages && npm run docs:copy:tmp:5x",
97
- "docs:prepare:publish:6x": "npm run docs:checkout:6x && npm run docs:merge:6x && npm run docs:clean:stable && npm run docs:generate && npm run docs:copy:tmp && npm run docs:checkout:gh-pages && npm run docs:copy:tmp:6x",
98
+ "docs:prepare:publish:6x": "npm run docs:checkout:6x && npm run docs:merge:6x && npm run docs:clean:stable && env DOCS_DEPLOY=true npm run docs:generate && npm run docs:move:6x:tmp && npm run docs:checkout:gh-pages && npm run docs:copy:tmp:6x",
98
99
  "docs:check-links": "blc http://127.0.0.1:8089 -ro",
99
100
  "lint": "eslint .",
100
101
  "lint-js": "eslint . --ext .js",
package/types/models.d.ts CHANGED
@@ -162,12 +162,12 @@ declare module 'mongoose' {
162
162
  * if you use `create()`) because with `bulkWrite()` there is only one network
163
163
  * round trip to the MongoDB server.
164
164
  */
165
- bulkWrite(
166
- writes: Array<mongodb.AnyBulkWriteOperation<T extends Document ? any : (T extends {} ? T : any)>>,
165
+ bulkWrite<DocContents = T>(
166
+ writes: Array<mongodb.AnyBulkWriteOperation<DocContents extends Document ? any : (DocContents extends {} ? DocContents : any)>>,
167
167
  options: mongodb.BulkWriteOptions & MongooseBulkWriteOptions & { ordered: false }
168
168
  ): Promise<mongodb.BulkWriteResult & { mongoose?: { validationErrors: Error[] } }>;
169
- bulkWrite(
170
- writes: Array<mongodb.AnyBulkWriteOperation<T extends Document ? any : (T extends {} ? T : any)>>,
169
+ bulkWrite<DocContents = T>(
170
+ writes: Array<mongodb.AnyBulkWriteOperation<DocContents extends Document ? any : (DocContents extends {} ? DocContents : any)>>,
171
171
  options?: mongodb.BulkWriteOptions & MongooseBulkWriteOptions
172
172
  ): Promise<mongodb.BulkWriteResult>;
173
173