Mongo Call does not remove parameters

假如想象 提交于 2021-02-11 15:04:22

问题


Im using node with mongo, and I want for the mongo get call to stop returning some values, such as _id and uid. Everything that ive read says that this call should work, but when I print the json value on my UI, it still has those values.

app.get('/users', async function(req, res){
    console.log("Getting User Info!");

    await client.connect();
    const db = client.db('database');
    var uidparam = req.header("uid");
    
    db.collection("users").findOne({"uid": uidparam}, { _id: 0, uid: 0, }, function(err, result) {
        if (err) throw err;
        res.send(result);
      });
});

Ive also tried

{ "_id": false, "uid": false, }

and

{ _id: false, uid: false, }

and

{ '_id': 0, 'uid': 0, }

回答1:


Following along with this example for Node, it looks like you need to specify a projection field for the options document. It would look like this:

{
  projection: {
    _id: 0,
    uid: 0
  }
}


来源:https://stackoverflow.com/questions/64627725/mongo-call-does-not-remove-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!