Skip to content

Commit

Permalink
Merge pull request #10014 from Automattic/5.12
Browse files Browse the repository at this point in the history
5.12
  • Loading branch information
vkarpov15 committed Mar 11, 2021
2 parents ff289ec + d7f852f commit b4e0ae5
Show file tree
Hide file tree
Showing 31 changed files with 686 additions and 155 deletions.
13 changes: 13 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
5.12.0 / 2021-03-11
===================
* feat(populate): add `transform` option that Mongoose will call on every populated doc #3775
* feat(query): make `Query#pre()` and `Query#post()` public #9784
* feat(document): add `Document#getPopulatedDocs()` to return an array of all populated documents in a document #9702 [IslandRhythms](https://github.com/IslandRhythms)
* feat(document): add `Document#getAllSubdocs()` to return an array of all single nested and array subdocuments #9764 [IslandRhythms](https://github.com/IslandRhythms)
* feat(schema): allow `schema` as a schema path name #8798 [IslandRhythms](https://github.com/IslandRhythms)
* feat(QueryCursor): Add batch processing for eachAsync #9902 [khaledosama999](https://github.com/khaledosama999)
* feat(connection): add `noListener` option to help with use cases where you're using `useDb()` on every request #9961
* feat(index): emit 'createConnection' event when user calls `mongoose.createConnection()` #9985
* feat(connection+index): emit 'model' and 'deleteModel' events on connections when creating and deleting models #9983
* feat(query): allow passing `explain` option to `Model.exists()` #8098 [IslandRhythms](https://github.com/IslandRhythms)

5.11.20 / 2021-03-11
====================
* fix(query+populate): avoid unnecessarily projecting in subpath when populating a path that uses an elemMatch projection #9973
Expand Down
5 changes: 4 additions & 1 deletion docs/api/querycursor.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
<span class="method-type">&laquo;Function&raquo;</span> </li></ul><h5>Returns:</h5><ul><li><span class="method-type">&laquo;Promise&raquo;</span> </li></ul><div><p>Marks this cursor as closed. Will stop streaming and subsequent calls to <code>next()</code> will error.</p> </div><hr class="separate-api-elements"><h3 id="querycursor_QueryCursor-eachAsync"><a href="#querycursor_QueryCursor-eachAsync">QueryCursor.prototype.eachAsync()</a></h3><h5>Parameters</h5><ul class="params"><li class="param">fn
<span class="method-type">&laquo;Function&raquo;</span> </li><li class="param">[options]
<span class="method-type">&laquo;Object&raquo;</span> </li><ul style="margin-top: 0.5em"><li>[options.parallel]
<span class="method-type">&laquo;Number&raquo;</span> the number of promises to execute in parallel. Defaults to 1.</li></ul><li class="param">[callback]
<span class="method-type">&laquo;Number&raquo;</span> the number of promises to execute in parallel. Defaults to 1.
<span class="method-type">&laquo;Object&raquo;</span><ul style="margin-top: 0.5em"><li>[options.batchSize]
<span class="method-type">&laquo;Number&raquo;</span> The size of documents processed by the passed in function to eachAsync (works with the parallel option)</li></ul>
</li></ul><li class="param">[callback]
<span class="method-type">&laquo;Function&raquo;</span> executed when all docs have been processed</li></ul><h5>Returns:</h5><ul><li><span class="method-type">&laquo;Promise&raquo;</span> </li></ul><div><p>Execute <code>fn</code> for every document in the cursor. If <code>fn</code> returns a promise, will wait for the promise to resolve before iterating on to the next one. Returns a promise that resolves when done.</p> </div><hr class="separate-api-elements"><h3 id="querycursor_QueryCursor-map"><a href="#querycursor_QueryCursor-map">QueryCursor.prototype.map()</a></h3><h5>Parameters</h5><ul class="params"><li class="param">fn
<span class="method-type">&laquo;Function&raquo;</span> </li></ul><h5>Returns:</h5><ul><li><span class="method-type">&laquo;QueryCursor&raquo;</span> </li></ul><div><p>Registers a transform function which subsequently maps documents retrieved via the streams interface or <code>.next()</code></p>

Expand Down
25 changes: 15 additions & 10 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ declare module 'mongoose' {
transaction(fn: (session: mongodb.ClientSession) => Promise<any>): Promise<any>;

/** Switches to a different database using the same connection pool. */
useDb(name: string, options?: { useCache?: boolean }): Connection;
useDb(name: string, options?: { useCache?: boolean, noListener?: boolean }): Connection;

/** The username specified in the URI */
user: string;
Expand Down 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 All @@ -384,6 +387,9 @@ declare module 'mongoose' {
/** Getter/setter, determines whether the document was removed or not. */
$isDeleted(val?: boolean): boolean;

/** Returns an array of all populated documents associated with the query */
$getPopulatedDocs(): Document[];

/**
* Returns true if the given path is nullish or only contains empty objects.
* Useful for determining whether this subdoc will get stripped out by the
Expand Down Expand Up @@ -2330,12 +2336,13 @@ declare module 'mongoose' {
close(callback: (err: CallbackError) => void): void;

/**
* Execute `fn` for every document in the cursor. If `fn` returns a promise,
* Execute `fn` for every document(s) in the cursor. If batchSize is provided
* `fn` will be executed for each batch of documents. If `fn` returns a promise,
* will wait for the promise to resolve before iterating on to the next one.
* Returns a promise that resolves when done.
*/
eachAsync(fn: (doc: DocType) => any, options?: { parallel?: number }): Promise<void>;
eachAsync(fn: (doc: DocType) => any, options?: { parallel?: number }, cb?: (err: CallbackError) => void): void;
eachAsync(fn: (doc: DocType| [DocType]) => any, options?: { parallel?: number, batchSize?: number }): Promise<void>;
eachAsync(fn: (doc: DocType| [DocType]) => any, options?: { parallel?: number, batchSize?: number }, cb?: (err: CallbackError) => void): void;

/**
* Registers a transform function which subsequently maps documents retrieved
Expand Down Expand Up @@ -2478,9 +2485,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 All @@ -2498,12 +2502,13 @@ declare module 'mongoose' {
close(callback: (err: CallbackError) => void): void;

/**
* Execute `fn` for every document in the cursor. If `fn` returns a promise,
* Execute `fn` for every document(s) in the cursor. If batchSize is provided
* `fn` will be executed for each batch of documents. If `fn` returns a promise,
* will wait for the promise to resolve before iterating on to the next one.
* Returns a promise that resolves when done.
*/
eachAsync(fn: (doc: any) => any, options?: { parallel?: number }): Promise<void>;
eachAsync(fn: (doc: any) => any, options?: { parallel?: number }, cb?: (err: CallbackError) => void): void;
eachAsync(fn: (doc: any) => any, options?: { parallel?: number, batchSize?: number }): Promise<void>;
eachAsync(fn: (doc: any) => any, options?: { parallel?: number, batchSize?: number }, cb?: (err: CallbackError) => void): void;

/**
* Registers a transform function which subsequently maps documents retrieved
Expand Down
7 changes: 2 additions & 5 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ Object.defineProperty(Connection.prototype, 'readyState', {
db.readyState = val;
}

// loop over relatedDbs on this connection and change their state
for (const k in this.relatedDbs) {
this.relatedDbs[k].readyState = val;
}

if (STATES.connected === val) {
this._hasOpened = true;
}
Expand Down Expand Up @@ -1309,6 +1304,8 @@ Connection.prototype.deleteModel = function(name) {
delete this.models[name];
delete this.collections[collectionName];
delete this.base.modelSchemas[name];

this.emit('deleteModel', model);
} else if (name instanceof RegExp) {
const pattern = name;
const names = this.modelNames();
Expand Down
Loading

0 comments on commit b4e0ae5

Please sign in to comment.