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

5.12 #10014

Merged
merged 51 commits into from
Mar 11, 2021
Merged

5.12 #10014

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
a31efa1
feat (document): Exposed $getAllSubdocs()
IslandRhythms Jan 4, 2021
ec5c540
feat: implemented getPopulatedDocs()
IslandRhythms Jan 4, 2021
d9763fc
Merge pull request #9764 from Automattic/gh9545
vkarpov15 Jan 5, 2021
2990fb6
fix: edited formatting of document..test.js and document.js
IslandRhythms Jan 5, 2021
f81e95b
fix: changed const result = [] to let result = []
IslandRhythms Jan 5, 2021
88616e4
fix: re-edited formatting
IslandRhythms Jan 5, 2021
5c6993f
fix: edited formatting
IslandRhythms Jan 5, 2021
5e8e7f7
feat: implemented getPopulatedDocs()
IslandRhythms Jan 5, 2021
9a102d1
feat: added $getPopulatedDocs to index.d.ts
IslandRhythms Jan 5, 2021
ef3038e
feat: Implemented setting explain flag
IslandRhythms Jan 5, 2021
538cd51
Update model.test.js
IslandRhythms Jan 5, 2021
485c910
fix: added space to fix linter error
IslandRhythms Jan 6, 2021
e871748
PR for mongoose
IslandRhythms Jan 7, 2021
c8072ef
fix: explain will now return an object
IslandRhythms Jan 7, 2021
97a4877
added second condition to check for undefined
IslandRhythms Jan 7, 2021
14cbfd9
separated if statments
IslandRhythms Jan 7, 2021
758bef7
fixed syntax error
IslandRhythms Jan 7, 2021
f632a6a
made requested changes
IslandRhythms Jan 7, 2021
c8a422d
chore: couple quick style fixes
vkarpov15 Jan 9, 2021
848867c
Merge pull request #9766 from Automattic/#9702
vkarpov15 Jan 9, 2021
3274823
chore: code review comments
vkarpov15 Jan 9, 2021
7517005
Merge pull request #9769 from Automattic/#8075
vkarpov15 Jan 9, 2021
7c7158c
style: fix lint
vkarpov15 Jan 9, 2021
0645745
Merge branch 'master' into 5.12
vkarpov15 Jan 9, 2021
d159885
fix: replaced this.schema with this.$__schema where appropriate
IslandRhythms Jan 21, 2021
7093c2b
made requested changes
IslandRhythms Jan 21, 2021
8c2691b
made more fixes
IslandRhythms Jan 21, 2021
c9befbf
made all requested changes
IslandRhythms Jan 21, 2021
7c55a77
made necessary changes
IslandRhythms Jan 21, 2021
07d663f
changed 1 line in document.js
IslandRhythms Jan 21, 2021
25ba5f1
added failing test
IslandRhythms Jan 21, 2021
2373c07
fix: gh-8798
IslandRhythms Jan 25, 2021
0739a4d
fix(document): avoid infinite recursion when using `schema` as a sche…
vkarpov15 Jan 26, 2021
0c3f4d7
fix: allow using `schema` as a pathname
vkarpov15 Jan 26, 2021
ae369ae
Merge branch 'master' into gh-8798
vkarpov15 Jan 26, 2021
31fdece
Merge branch 'master' into 5.12
vkarpov15 Jan 26, 2021
fa3b60a
Merge pull request #9845 from Automattic/gh-8798
vkarpov15 Jan 26, 2021
007fb69
feat: add batch processing for eachAsync
khaledosama999 Feb 12, 2021
c581c60
Merge pull request #9902 from khaledosama999/gh-9861
vkarpov15 Feb 15, 2021
f60dc12
Merge branch 'master' into 5.12
vkarpov15 Feb 20, 2021
83fd8aa
Merge branch '5.12' of github.com:Automattic/mongoose into 5.12
vkarpov15 Feb 21, 2021
78efd9f
feat(populate): add `transform` option that Mongoose will call on eve…
vkarpov15 Feb 21, 2021
e5e2937
fix(populate): mostly working `transform` option for virtual populate…
vkarpov15 Feb 25, 2021
a7ceb7e
fix(populate): make transform option work consistently for both virtu…
vkarpov15 Mar 4, 2021
56bd888
Merge branch 'master' into 5.12
vkarpov15 Mar 4, 2021
aebbcc1
feat(query): make `Query#pre()` and `Query#post()` public
vkarpov15 Mar 4, 2021
5c5fcbc
feat(connection+index): emit 'model' and 'deleteModel' events on conn…
vkarpov15 Mar 4, 2021
a57875b
feat(index): emit 'createConnection' event when user calls `mongoose.…
vkarpov15 Mar 4, 2021
6c55b69
feat(connection): add `noListener` option to help with use cases wher…
vkarpov15 Mar 10, 2021
2170a8b
Merge branch 'master' into 5.12
vkarpov15 Mar 11, 2021
d7f852f
chore: release 5.12.0
vkarpov15 Mar 11, 2021
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
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