Skip to content

Commit

Permalink
feat (document): Exposed $getAllSubdocs()
Browse files Browse the repository at this point in the history
  • Loading branch information
IslandRhythms committed Jan 4, 2021
1 parent fce72fe commit a31efa1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ declare module 'mongoose' {
/** This documents __v. */
__v?: number;

/* Get all subdocs (by bfs) */
$getAllSubdocs(): Document[];

/** Don't run validation on this path or persist changes to this path. */
$ignore(path: string): void;

Expand Down Expand Up @@ -2349,9 +2352,6 @@ declare module 'mongoose' {

/** Appends new custom $unwind operator(s) to this aggregate pipeline. */
unwind(...args: any[]): this;

/** Appends new custom $project operator to this aggregate pipeline. */
project(arg: any): this
}

class AggregationCursor extends stream.Readable {
Expand Down
12 changes: 6 additions & 6 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ Document.prototype.$session = function $session(session) {
this.$__.session = session;

if (!this.ownerDocument) {
const subdocs = this.$__getAllSubdocs();
const subdocs = this.$getAllSubdocs();
for (const child of subdocs) {
child.$session(session);
}
Expand Down Expand Up @@ -2271,7 +2271,7 @@ function _getPathsToValidate(doc) {
Object.keys(doc.$__.activePaths.states.default).forEach(addToPaths);
function addToPaths(p) { paths.add(p); }

const subdocs = doc.$__getAllSubdocs();
const subdocs = doc.$getAllSubdocs();
const modifiedPaths = doc.modifiedPaths();
for (const subdoc of subdocs) {
if (subdoc.$basePath) {
Expand Down Expand Up @@ -2942,7 +2942,7 @@ Document.prototype.$__undoReset = function $__undoReset() {
}
}

for (const subdoc of this.$__getAllSubdocs()) {
for (const subdoc of this.$getAllSubdocs()) {
subdoc.$__undoReset();
}
};
Expand Down Expand Up @@ -3070,13 +3070,13 @@ Document.prototype.$__getArrayPathsToValidate = function() {
/**
* Get all subdocs (by bfs)
*
* @api private
* @method $__getAllSubdocs
* @api public
* @method $getAllSubdocs
* @memberOf Document
* @instance
*/

Document.prototype.$__getAllSubdocs = function() {
Document.prototype.$getAllSubdocs = function $getAllSubdocs() {
DocumentArray || (DocumentArray = require('./types/documentarray'));
Embedded = Embedded || require('./types/embedded');

Expand Down
2 changes: 1 addition & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3386,7 +3386,7 @@ function _setIsNew(doc, val) {
doc.emit('isNew', val);
doc.constructor.emit('isNew', val);

const subdocs = doc.$__getAllSubdocs();
const subdocs = doc.$getAllSubdocs();
for (const subdoc of subdocs) {
subdoc.isNew = val;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/removeSubdocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(schema) {
}

const _this = this;
const subdocs = this.$__getAllSubdocs();
const subdocs = this.$getAllSubdocs();

each(subdocs, function(subdoc, cb) {
subdoc.$__remove(cb);
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/saveSubdocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(schema) {
}

const _this = this;
const subdocs = this.$__getAllSubdocs();
const subdocs = this.$getAllSubdocs();

if (!subdocs.length) {
next();
Expand Down Expand Up @@ -43,7 +43,7 @@ module.exports = function(schema) {
}

const _this = this;
const subdocs = this.$__getAllSubdocs();
const subdocs = this.$getAllSubdocs();

if (!subdocs.length) {
next();
Expand Down

0 comments on commit a31efa1

Please sign in to comment.