Document.prototype.directModifiedPaths()

Returns:
  • «Array»

Returns the list of paths that have been directly modified. A direct modified path is a path that you explicitly set, whether via doc.foo = 'bar', Object.assign(doc, { foo: 'bar' }), or doc.set('foo', 'bar').

A path a may be in modifiedPaths() but not in directModifiedPaths() because a child of a was directly modified.

Example

  1. const schema = new Schema({ foo: String, nested: { bar: String } });
  2. const Model = mongoose.model('Test', schema);
  3. await Model.create({ foo: 'original', nested: { bar: 'original' } });
  4. const doc = await Model.findOne();
  5. doc.nested.bar = 'modified';
  6. doc.directModifiedPaths(); // ['nested.bar']
  7. doc.modifiedPaths(); // ['nested', 'nested.bar']