gpt4 book ai didi

node.js - Mongoose 检索没有 _id 字段的数据

转载 作者:IT老高 更新时间:2023-10-28 21:54:04 28 4
gpt4 key购买 nike

我想从我的 Node.js 应用程序中的 Mongoose 设置中检索一些数据。我注意到无论我写什么作为字段选择,我总是得到 _id 字段。有办法不取吗?这就是我现在的做法:

Transaction.find({username : user.username}, ['uniqueId', 'timeout', 'confirmation_link', 'item_name'], function(err, txs){
console.log("user : " + user.username + " with txs: " + txs);
callback(txs);
});

并记录包含 _id 字段的结果。

最佳答案

另一种方法是使用带有前缀 - 的文本参数,这将从结果中排除这个或那个字段:

Entity.find({ ... }, '-_id field1 field2', function(err, entity) {
console.log(entity); // { field1: '...', field2: '...' }
});

关于node.js - Mongoose 检索没有 _id 字段的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9598505/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com