Reputation: 9746
I am stuck in the following issue :-
var userid = req.params.userid;
var category = req.params.category;
// category can be basicinfo, address, contactinfo, etc
var selection = {
category: 1
};
User.find({ _id: userid}, selection){.......}
The category
which is passed as parameter doesn't reflect in the query selection. so, when i run the above code it runs like this: -
`User.find({ _id: userid}, category: 1){.......}`
What i expect is :-
`User.find({ _id: userid}, basicinfo: 1){.......}`
What is solution for this?
Upvotes: 0
Views: 36
Reputation: 13119
var category = req.params.category;
var selection = {};
selection[category] = 1;
User.find({_id:userid}, selection){...}
Upvotes: 2