Mongo Call不会删除参数 [英] Mongo Call does not remove parameters

查看:36
本文介绍了Mongo Call不会删除参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mongo中使用node,我想让mongo得到调用以停止返回一些值,例如_id和uid.我读过的所有内容都说此调用应该可以,但是当我在用户界面上打印json值时,它仍然具有这些值.

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);
      });
});

我也尝试过

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

{ _id: false, uid: false, }

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

推荐答案

以及

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
  }
}

这篇关于Mongo Call不会删除参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆