gpt4 book ai didi

node.js - MongoDB find() 可以返回不同的记录吗?

转载 作者:太空宇宙 更新时间:2023-11-04 00:39:20 26 4
gpt4 key购买 nike

这是一种调用 MongoDB find() 方法并获取不同记录的方法吗?或者我应该循环结果集?

collection.find({
'recordType' : recordType,
'date' : {
$gte : new Date(dateFrom)
},
'operation' : 'delete'
}, {
fields : {
'date' : 0,
'operation' : 0
}
}).toArray(function (err, results) {

jsonResult.push(results);

response.write(JSON.stringify(jsonResult));
response.end()
});

最佳答案

“collection.find”没有区别。您可能需要单独使用不同的。但是,您可以在以下选项中包含过滤条件。

distinct(key[, query][, options], callback)

示例:

testMethod - 该字段的不同值;build - 是过滤条件

collection.distinct('testMethod', {'build':1}, function(err, item) {
console.log("item:" + JSON.stringify(item));

db.close();
});

关于node.js - MongoDB find() 可以返回不同的记录吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37529014/

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