Exclude fields from result in MongoDB monk

前端 未结 2 471
天涯浪人
天涯浪人 2021-01-11 19:18

I want to exclude some fields from result. I have code:

users = db.select(\'users\');

users.find( {}, { sort: { points:1 }, privateKey:0, publicKey:0}, func         


        
2条回答
  •  星月不相逢
    2021-01-11 20:10

    According to documentation first argument in find is filter and second is projection .But you have used sort . It will not able to interpret . You are trying to confuse projection with sort .Sorting should be after find and projection.

    You can write projection like { field1: , field2: ... }

    Note : The find() method always includes the _id field even if the field is not explicitly stated to return in the projection parameter.

     users.find({}, { privateKey: 0, publicKey: 0 }).sort({points: 1}).toArray(
               function (err, data) {
                          res.send(data);
                 });
    

提交回复
热议问题