node.js - 聚合上的 Mongoskin 光标
问题描述
我在 nodejs 中使用 mongoskin 进行数据库查询。
我无法在聚合查询上使用游标,而在查找查询的情况下它工作正常。
//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”
解决方案
我遇到过同样的问题。我为它创建了一个库。它允许使用聚合编写 foreach 并且可以使用游标运行。mongoskin 光标
示例:db.collection('collectionname').aggregate().forEach(function(){}); db.collection('collectionname').aggregateAsync().then(function(){});
推荐阅读
- qt - PySide2 QThread 错误:QThread:在线程仍在运行时被销毁
- node.js - 使用 Mongodb ($or + $and) 创建渐进式过滤器
- html - 使用 CSS 编辑单个图像。带有类的 Img Src 仍在更改网站上的所有图像
- sql - 为什么常量的类型转换会破坏查询性能
- python - 带有日期时间的 Matplotlib 绘图
- php - axios api调用不适用于vue路由器路由路径laravel项目
- visual-studio-code - 我可以同时将 VS Code 用于两个不同的项目吗?
- python - 如果我调试或运行它,为什么会有两个不同的结果?
- python - Django Defect-dojo:aws-prowler 上传失败
- android - java.lang.RuntimeException: android.view.InflateException