[英]FindOne() working to return records, but cannot use MongoDB aggregate query (sum records for ids) for Node.js
[英]How to skip the 50 records and after that find the matched records in mongodb by using findOne query in node.js
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)
findOne()
不支持skip()
,因为检索的是文档而不是游标。 您可以改用以下方法:
db.getCollection('Gps').find({captureDateTime :"a5"}).skip(50).limit(1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.