2017-08-08 101 views
0

我想使用nodejs在单个查询中删除和检索1000条记录。请任何人都可以帮助我。需要mongodb查询以在单个查询中检索和删除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。它快速执行,但删除工作慢慢记录。

+0

其实际上我不需要的是单个查询我想用高效率读取和删除1000条记录 –

回答

1

为什么不使用$in删除调用呢?

global.queuetable.remove({ _id: {$in: queueRecords.map((record) => record._id)} }, function(err, removeSuccess) {));