Frage

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?

War es hilfreich?

Lösung

var category = req.params.category;
var selection = {};
selection[category] = 1;
User.find({_id:userid}, selection){...}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top