Skip to content

Commit 22c6c33

Browse files
committedJul 29, 2018
fix(query): propagate top-level session down to populate()
Fix #6754
1 parent 0f24449 commit 22c6c33

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed
 

‎lib/query.js

-1
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,6 @@ Query.prototype._find = function(callback) {
16011601
}
16021602

16031603
const pop = helpers.preparePopulationOptionsMQ(_this, mongooseOptions);
1604-
pop.__noPromise = true;
16051604
completeManyOptions.populated = pop;
16061605
_this.model.populate(docs, pop, function(err, docs) {
16071606
if (err) return callback(err);

‎lib/queryhelpers.js

+13
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ exports.preparePopulationOptionsMQ = function preparePopulationOptionsMQ(query,
4848
forEach(makeLean(options.lean));
4949
}
5050

51+
const session = get(query, 'options.session', null);
52+
if (session != null) {
53+
pop.forEach(path => {
54+
if (path.options == null) {
55+
path.options = { session: session };
56+
return;
57+
}
58+
if (!('session' in path.options)) {
59+
path.options.session = session;
60+
}
61+
});
62+
}
63+
5164
return pop;
5265
};
5366

0 commit comments

Comments
 (0)
Please sign in to comment.