Reputation: 53
sample.getCollection()
.find({},{"name":0,_id:0})
.toArray(function(err1,res)
{
if(err1)
return console.log(err1);
console.log(res);
});
I have been trying to hide the fields in the find query of MongoDb in Node.js , but Projection part is not working as expected. Neither it is showing any error in the query. It is showing all the available fields in the all documents .
Upvotes: 0
Views: 100
Reputation: 1615
find({},{"name":0,_id:0})
is native mongodb syntax.
Try something like this -
sample.getCollection()
.find({}).project({"name":0,_id:0})
.toArray(function(err1,res)
{
if(err1)
return console.log(err1);
console.log(res);
});
Upvotes: 1