populate match not working
See original GitHub issueWhat 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' });
Issue Analytics
- State:
- Created 10 years ago
- Comments:15 (1 by maintainers)
Top Results From Across the Web
Mongoose - Populate not filtering correctly - Stack Overflow
Match works when fields are part of the schema of the referred object. An option is to remove the status and balance fields...
Read more >Mongoose v6.8.2: Query Population
Populate Virtuals: The Match Option ... You can also set the match option to a function. That allows configuring the match based on...
Read more >mongoose populate function is not working. Can anyone tell me why ...
Guy's why this query is not working to fetch match data from two table order and user. although everything seem fine... Query code:...
Read more >Populate doesnt work on mongoose
I've been trying to populate Auth with Voters Document but it doesnt seem to work. Sorry for the long a$$ code const voterSchema...
Read more >Mongoose: Problem populating nested array with aggregate
There are two problems with this query. PROBLEM 1: It only populates institution because the institution $lookup stage was added after the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+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.