我在nodejs中使用mongoskin进行db查询。
我无法在聚合查询上使用游标,而在查找查询的情况下,游标工作得很好。
//This code is working fine
var cursor = db.collection('users').find();
cursor.forEach(function(user){
console.log(user);
})
//The below query is not working
var cursor = db.collection('users').aggregate([{$sort:{username:1}}]);
cursor.forEach(function(user){
console.log(user);
})
//error - cursor.forEach is not a function是否有使用mongoskin在聚合上使用游标的替代方法?
"mongoskin":"^2.1.0“
发布于 2019-12-29 15:23:03
我也有过同样的问题。我为此创建了一个图书馆。它允许使用聚合编写foreach,并且可以使用游标运行。蒙戈斯金光标
例子: db.collection('collectionname').aggregate().forEach(function(){});db.collection('collectionname').aggregateAsync().then(function(){});
https://stackoverflow.com/questions/59356569
复制相似问题