Skip to content

Commit

Permalink
post hook find does now return an array but gh-9435 and gh-8235 fail
Browse files Browse the repository at this point in the history
  • Loading branch information
IslandRhythms committed Mar 16, 2021
1 parent 86b4574 commit b983819
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/cursor/QueryCursor.js
Expand Up @@ -441,7 +441,7 @@ function _populateBatch() {

function _nextDoc(ctx, doc, pop, callback) {
if (ctx.query._mongooseOptions.lean) {
return ctx.model.hooks.execPost('find', ctx.query, [doc], err => {
return ctx.model.hooks.execPost('find', ctx.query, [[doc]], err => {
if (err != null) {
return callback(err);
}
Expand All @@ -453,7 +453,7 @@ function _nextDoc(ctx, doc, pop, callback) {
if (err != null) {
return callback(err);
}
ctx.model.hooks.execPost('find', ctx.query, [doc], err => {
ctx.model.hooks.execPost('find', ctx.query, [[doc]], err => {
if (err != null) {
return callback(err);
}
Expand All @@ -480,7 +480,7 @@ function _waitForCursor(ctx, cb) {
*/

function _create(ctx, doc, populatedIds, cb) {
const instance = helpers.createModel(ctx.query.model, [doc], ctx.query._fields);
const instance = helpers.createModel(ctx.query.model, doc, ctx.query._fields);
const opts = populatedIds ?
{ populated: populatedIds } :
undefined;
Expand Down
7 changes: 2 additions & 5 deletions test/query.cursor.test.js
Expand Up @@ -714,18 +714,15 @@ describe('QueryCursor', function() {
it('returns array for schema hooks gh-9982', () => {
const testSchema = new mongoose.Schema({ name: String });
testSchema.post('find', (result) => {

console.log('result', result);
console.log(new Error().stack);
//assert.ok(Array.isArray(result));
assert.ok(Array.isArray(result));
});
const Movie = db.model('Movie', testSchema);
return co(function*() {
yield Movie.deleteMany({});
yield Movie.create({ name: 'Daniel' }, { name: 'Val' }, { name: 'Daniel' });
const test = Movie.find({ name: 'Daniel' }).cursor();
test.next().then(doc => {
console.log('doc', doc);
assert.ok(doc,doc);
});
});
});
Expand Down

0 comments on commit b983819

Please sign in to comment.