문제

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?

도움이 되었습니까?

해결책

var category = req.params.category;
var selection = {};
selection[category] = 1;
User.find({_id:userid}, selection){...}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top