mongoose 8.5.4 → 8.5.5

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.
package/lib/document.js CHANGED
@@ -842,7 +842,7 @@ function init(self, obj, doc, opts, prefix) {
842
842
  */
843
843
 
844
844
  Document.prototype.updateOne = function updateOne(doc, options, callback) {
845
- const query = this.constructor.updateOne({ _id: this._id }, doc, options);
845
+ const query = this.constructor.updateOne({ _id: this._doc._id }, doc, options);
846
846
  const self = this;
847
847
  query.pre(function queryPreUpdateOne(cb) {
848
848
  self.constructor._middleware.execPre('updateOne', self, [self], cb);
@@ -883,7 +883,7 @@ Document.prototype.updateOne = function updateOne(doc, options, callback) {
883
883
 
884
884
  Document.prototype.replaceOne = function replaceOne() {
885
885
  const args = [...arguments];
886
- args.unshift({ _id: this._id });
886
+ args.unshift({ _id: this._doc._id });
887
887
  return this.constructor.replaceOne.apply(this.constructor, args);
888
888
  };
889
889
 
@@ -3050,7 +3050,7 @@ Document.prototype.$__validate = function(pathsToValidate, options, callback) {
3050
3050
  } else if (val != null && val.$__ != null && val.$__.wasPopulated) {
3051
3051
  // Array paths, like `somearray.1`, do not show up as populated with `$populated()`,
3052
3052
  // so in that case pull out the document's id
3053
- val = val._id;
3053
+ val = val._doc._id;
3054
3054
  }
3055
3055
  const scope = _this.$__.pathsToScopes != null && path in _this.$__.pathsToScopes ?
3056
3056
  _this.$__.pathsToScopes[path] :
@@ -15,7 +15,7 @@ class ParallelSaveError extends MongooseError {
15
15
  */
16
16
  constructor(doc) {
17
17
  const msg = 'Can\'t save() the same doc multiple times in parallel. Document: ';
18
- super(msg + doc._id);
18
+ super(msg + doc._doc._id);
19
19
  }
20
20
  }
21
21
 
@@ -16,7 +16,7 @@ class ParallelValidateError extends MongooseError {
16
16
  */
17
17
  constructor(doc) {
18
18
  const msg = 'Can\'t validate() the same doc multiple times in parallel. Document: ';
19
- super(msg + doc._id);
19
+ super(msg + doc._doc._id);
20
20
  }
21
21
  }
22
22
 
@@ -17,7 +17,7 @@ class VersionError extends MongooseError {
17
17
  */
18
18
  constructor(doc, currentVersion, modifiedPaths) {
19
19
  const modifiedPathsStr = modifiedPaths.join(', ');
20
- super('No matching document found for id "' + doc._id +
20
+ super('No matching document found for id "' + doc._doc._id +
21
21
  '" version ' + currentVersion + ' modifiedPaths "' + modifiedPathsStr + '"');
22
22
  this.version = currentVersion;
23
23
  this.modifiedPaths = modifiedPaths;
@@ -115,6 +115,9 @@ module.exports = function discriminator(model, name, schema, tiedValue, applyPlu
115
115
  }
116
116
  }
117
117
 
118
+ // Shallow clone `obj` so we can add additional properties without modifying original
119
+ // schema. `Schema.prototype.clone()` copies `obj` by reference, no cloning.
120
+ schema.obj = { ...schema.obj };
118
121
  mergeDiscriminatorSchema(schema, baseSchema);
119
122
 
120
123
  // Clean up conflicting paths _after_ merging re: gh-6076
@@ -626,7 +626,7 @@ function _getLocalFieldValues(doc, localField, model, options, virtual, schema)
626
626
 
627
627
  function convertTo_id(val, schema) {
628
628
  if (val != null && val.$__ != null) {
629
- return val._id;
629
+ return val._doc._id;
630
630
  }
631
631
  if (val != null && val._id != null && (schema == null || !schema.$isSchemaMap)) {
632
632
  return val._id;
@@ -636,7 +636,7 @@ function convertTo_id(val, schema) {
636
636
  const rawVal = val.__array != null ? val.__array : val;
637
637
  for (let i = 0; i < rawVal.length; ++i) {
638
638
  if (rawVal[i] != null && rawVal[i].$__ != null) {
639
- rawVal[i] = rawVal[i]._id;
639
+ rawVal[i] = rawVal[i]._doc._id;
640
640
  }
641
641
  }
642
642
  if (utils.isMongooseArray(val) && val.$schema()) {
@@ -17,11 +17,11 @@ const utils = require('../../utils');
17
17
  */
18
18
 
19
19
  module.exports = function markArraySubdocsPopulated(doc, populated) {
20
- if (doc._id == null || populated == null || populated.length === 0) {
20
+ if (doc._doc._id == null || populated == null || populated.length === 0) {
21
21
  return;
22
22
  }
23
23
 
24
- const id = String(doc._id);
24
+ const id = String(doc._doc._id);
25
25
  for (const item of populated) {
26
26
  if (item.isVirtual) {
27
27
  continue;
package/lib/model.js CHANGED
@@ -2345,7 +2345,7 @@ Model.findByIdAndUpdate = function(id, update, options) {
2345
2345
 
2346
2346
  // if a model is passed in instead of an id
2347
2347
  if (id instanceof Document) {
2348
- id = id._id;
2348
+ id = id._doc._id;
2349
2349
  }
2350
2350
 
2351
2351
  return this.findOneAndUpdate.call(this, { _id: id }, update, options);
@@ -3408,7 +3408,7 @@ Model.bulkSave = async function bulkSave(documents, options) {
3408
3408
  documents.map(async(document) => {
3409
3409
  const documentError = bulkWriteError && bulkWriteError.writeErrors.find(writeError => {
3410
3410
  const writeErrorDocumentId = writeError.err.op._id || writeError.err.op.q._id;
3411
- return writeErrorDocumentId.toString() === document._id.toString();
3411
+ return writeErrorDocumentId.toString() === document._doc._id.toString();
3412
3412
  });
3413
3413
 
3414
3414
  if (documentError == null) {
@@ -4436,7 +4436,7 @@ function _assign(model, vals, mod, assignmentOpts) {
4436
4436
 
4437
4437
  for (let __val of _val) {
4438
4438
  if (__val instanceof Document) {
4439
- __val = __val._id;
4439
+ __val = __val._doc._id;
4440
4440
  }
4441
4441
  key = String(__val);
4442
4442
  if (rawDocs[key]) {
package/lib/query.js CHANGED
@@ -3380,9 +3380,9 @@ Query.prototype._findOneAndUpdate = async function _findOneAndUpdate() {
3380
3380
  if (!this._update || Object.keys(this._update).length === 0) {
3381
3381
  if (options.upsert) {
3382
3382
  // still need to do the upsert to empty doc
3383
- const doc = clone(this._update);
3384
- delete doc._id;
3385
- this._update = { $set: doc };
3383
+ const $set = clone(this._update);
3384
+ delete $set._id;
3385
+ this._update = { $set };
3386
3386
  } else {
3387
3387
  this._executionStack = null;
3388
3388
  const res = await this._findOne();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "8.5.4",
4
+ "version": "8.5.5",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -87,8 +87,8 @@ declare module 'mongoose' {
87
87
  'createdAt' | 'updatedAt'
88
88
  > as TimestampOptions[K] extends true
89
89
  ? K
90
- : TimestampOptions[K] extends string
91
- ? TimestampOptions[K]
90
+ : TimestampOptions[K] extends `${infer TimestampValue}`
91
+ ? TimestampValue
92
92
  : never]: NativeDate;
93
93
  } & T
94
94
  : T