Skip to content

Commit

Permalink
fix(query): propagate top-level session down to populate()
Browse files Browse the repository at this point in the history
Fix #6754
  • Loading branch information
vkarpov15 committed Jul 29, 2018
1 parent 0f24449 commit 22c6c33
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/query.js
Expand Up @@ -1601,7 +1601,6 @@ Query.prototype._find = function(callback) {
}

const pop = helpers.preparePopulationOptionsMQ(_this, mongooseOptions);
pop.__noPromise = true;
completeManyOptions.populated = pop;
_this.model.populate(docs, pop, function(err, docs) {
if (err) return callback(err);
Expand Down
13 changes: 13 additions & 0 deletions lib/queryhelpers.js
Expand Up @@ -48,6 +48,19 @@ exports.preparePopulationOptionsMQ = function preparePopulationOptionsMQ(query,
forEach(makeLean(options.lean));
}

const session = get(query, 'options.session', null);
if (session != null) {
pop.forEach(path => {
if (path.options == null) {
path.options = { session: session };
return;
}
if (!('session' in path.options)) {
path.options.session = session;
}
});
}

return pop;
};

Expand Down

0 comments on commit 22c6c33

Please sign in to comment.