node.js - 如何跳过 50 条记录,然后在 node.js 中使用 findOne 查询在 mongodb 中查找匹配的记录
问题描述
dbo.collection('Gps').findOne({$skip: 50}, { captureDateTime :a5},function (err, result) {
if (result) {
dbo.collection("OBD").insertOne({ sensortype: 'OBD', captureDateTime: result.captureDateTime, vehiculeData: b5 }, function (err, result) {
if (err) throw err;
else
console.log('OBD matched with GPS');
})
}
});
它没有得到正确的结果。我想跳过 50 条记录,然后从剩余的记录中我想要基于捕获时间匹配的记录并将其推送到 OBD 集合中。
我也试过
dbo.collection('Gps').aggregate([
{$skip : 50},
{ $match : { captureDateTime : a5 } }
]).toArray( function (err, result) {
if (result) {
dbo.collection("OBD").insertOne({ sensortype: 'OBD', captureDateTime: result.captureDateTime, vehiculeData: b5 }, function (err, result) {
if (err) throw err;
else
console.log('OBD matched with GPS');
})
}
});
解决方案
可能这可以解决您的问题链接:https ://www.w3resource.com/mongodb/mongodb-skip-limit.php
dbo.collection('Gps').findOne().skip(50)
推荐阅读
- ruby-on-rails - Rails 模式转储显示 NameError: undefined method `attributes' for class `Nokogiri::XML::AttributeDecl'
- spring-boot - 如何使用 Spring Cloud Sleuth 更改 REST Endpoint 的 Span 名称
- python - FLASK 应用程序:通过另一个脚本从表单发送数据,而一个“输入”是动态段落
- linux - /linux/usr/include/asm-generic/socket.h:123:5:警告:“__BITS_PER_LONG”未定义,计算结果为 0 [-Wundef]
- android - 如何为 Instagram 克隆构建 Cloud Firestore 数据?
- mysql - 如何对返回多个值的mysql中的查询执行计算
- python - `multiprocessing` 与 `concurrent.futures` 中的 Max Workers
- python - 将所有 50 朵 setosa 花的标签分配给一个数组
- intellij-idea - 将现有变量包装为 IntelliJ 代码编辑器中新类型方法调用的参数
- docker - 使用特定 USER id 在 Redhat Openshift 中创建部署