首页 > 解决方案 > 如何跳过 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');
                            })
                        }
                    });

标签: node.jsmongodb

解决方案


可能这可以解决您的问题链接:https ://www.w3resource.com/mongodb/mongodb-skip-limit.php

dbo.collection('Gps').findOne().skip(50)

推荐阅读