Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat (document): Exposed $getAllSubdocs() #9764

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be a blocker, but I wonder how this change got here... Merge issue of some sort?

}

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