findOne 忽略投影参数

问题描述 投票:0回答:1

我正在使用 mongoDB 6

还有这个查询

const client_res = await user_col.findOne(matching_cond, {
        _id: 1,
      });

将返回完整文档。不管我把第二个参数的文档放进去,它都被完全忽略了

https://www.mongodb.com/docs/v6.0/reference/method/db.collection.findOne/

mongodb mongodb-query
1个回答
0
投票

您链接的文档网站说

mongosh方法
本页记录了 mongosh 方法。这不是 数据库命令或特定语言驱动程序的文档,例如 作为 Node.js。

数据库命令参见find命令。

有关 MongoDB API 驱动程序,请参阅特定语言的 MongoDB 驱动程序文档。

有关旧版 mongo shell 文档,请参阅文档 对于相应的 MongoDB Server 版本:

mongo shell v4.4

因此您需要查找 Node.js 驱动程序文档。例如投影

const client_res = await user_col.findOne(matching_cond).project({ _id: 1 });
© www.soinside.com 2019 - 2024. All rights reserved.