mongoose: populate match not working
What is wrong about my code? Tried to filter using match in populate but only getting null for b_id:
my code is as follows:
exports.search = function (req, res) {
var b = req.body.b;
var a = req.body.a;
J.find()
.populate({
path: 'b_id',
match: {name: b},
model: B
})
.populate({
path: 'w_id',
model: W
})
.exec(function (err, j) {
W.populate(j, {
path: 'w_id.a_id',
model: A
}, function (err, j) {
console.log(j);
});
});
}
everything works fine I leave out the match and vars a and b are also filled correctly.
Any suggestions?
Many thanks!
EDIT:
These are my schemas:
var B = new Schema({
_id : Number,
name : String
}, { collection: 'b' });
var A = new Schema({
_id : Number,
name : String
}, { collection: 'a' });
var W = new Schema({
_id : Number,
a_id : { type: Number, ref: 'a' },
bez : String
}, { collection: 'w' });
var J = new Schema({
_id : Number,
b_id : { type: Number, ref: 'b' },
w_id : { type: Number, ref: 'w' },
s1 : String,
e1 : String,
s2 : String,
e2 : String,
bdh : String
}, { collection: 'j' });
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Comments: 15 (1 by maintainers)
+1
Populate match does not filter. It just returns all the records.
I have inserted 4 records in Rule schema with only one record have method equals POST, but with the code, I can query out 4 records.
match does not work. When i test it with mocha it works fine but the same with angular fails.
If i remove match then it works in angular.
Program.find({‘isActive’: true}).populate({ path: ‘network’, match: { isVisible: true }, select: ‘_id name’ }).exec(function (err, programs) { res.json(programs); });