Skip to content

Commit b88d134

Browse files
committed
adding back the $query so I can pass hints
1 parent 95c6799 commit b88d134

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

lib/tree.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,17 @@ function tree(schema, options) {
197197
recursive = recursive || false;
198198

199199
if (recursive) {
200-
filters['path'] = {$regex: '^' + this.path + pathSeparator}
201-
}
202-
else {
203-
filters['parent'] = this._id
200+
if(filters['$query']){
201+
filters['$query']['path'] = {$regex: '^' + this.path + pathSeparator};
202+
} else {
203+
filters['path'] = {$regex: '^' + this.path + pathSeparator};
204+
}
205+
} else {
206+
if(filters['$query']){
207+
filters['$query']['parent'] = this._id;
208+
} else {
209+
filters['parent'] = this._id;
210+
}
204211
}
205212

206213
return this.model(this.constructor.modelName).find(filters, fields, options, next);
@@ -252,7 +259,11 @@ function tree(schema, options) {
252259
ids.pop();
253260
}
254261

255-
filters['_id'] = {$in: ids};
262+
if(filters['$query']){
263+
filters['$query']['_id'] = {$in: ids};
264+
} else {
265+
filters['_id'] = {$in: ids};
266+
}
256267

257268
return this.model(this.constructor.modelName).find(filters, fields, options, next);
258269
};

0 commit comments

Comments
 (0)