【发布时间】:2017-08-08 19:35:21
【问题描述】:
我想使用 nodejs 在单个查询中删除和检索 1000 条记录。请任何可以帮助我的人。
queuetable.find({$query:{ Status : 0, CommunityId: { '$in': objconfig.queryCommunityIds[varCommunityId]},
DateReceived: { $gte: objcommon.timeFormat(date) } },
$hint:{Status:1,CommunityId:1,DateReceived:1}}, {}, { limit: 1000 },
function(err, queueRecords) {
callback(splitNotifications(function(notificationDet) {}, queueRecords, notificationCounter, browserCounter));
})
var splitNotifications = function(callback, queueRecords, notificationCounter, browserCounter) {
if(notificationCounter < queueRecords.length) {
global.queuetable.remove( { _id: queueRecords[notificationCounter]._id }, function(err, removeSuccess) {
console.log('removed record');
if (err){
objcommon.mongodberrorlog(objcommon.mongoTime(), err.stack, 'Error In queueOthers queue update');
// console.log('queuetable update failed in splitBrowsers.. :: Time :: '+objcommon.mongoTime()+' :: MatriId :: '+queueRecords[notificationCounter].MatriId);
process.exit(1);
}
});
logRecord[queueRecords[notificationCounter].MatriId] = {
"startTime" :0,
"endTime" :0,
"logInsertStartTime":0,
"logInsertEndTime":0,
"gcmStartTime" :0,
"gcmEndTime":0,
"gcmTime":0,
"totSentTime":0,
"browserCounter": 0,
"notificationType":0,
"DateSent":queueRecords[notificationCounter].DateSent
};
logRecord[queueRecords[notificationCounter].MatriId].startTime = getCurrentTime();
notificationCounter++;
callback(splitNotifications(function(notificationDet) {}, queueRecords, notificationCounter, browserCounter));
}
}
我想使用 nodejs 在单个查询中删除和检索 1000 条记录。请任何可以帮助我的人。在上面的代码中,我递归地调用 splitNotifications。它执行速度很快,但删除了工作缓慢的记录。
【问题讨论】:
-
它实际上并不重复我需要的是单个查询我想高效地读取和删除 1000 条记录