Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Private
  • Views: 78
  • Last Modified:

MongoDB Record Delete using JavaScript

I am trying to delete a bunch of records from MongoDB, but am having some issues with my JavaScript. It seems to go through the first 10 records and stop. Here is what I have so far:

function getObjectIDs() {
          var IDs = db.mycollection.find({log:{$lt:ISODate('2013-06-01T00:23:24.154Z')}}, {_id:1});
          return IDs;
}

function removeID(db, userId) {

          db.mysecondcollection.remove({user:userId});

}

var IDs = getObjectIDs();

IDs.forEach(function(ID) {
          removeID(db, ID._ID);
});

Open in new window


Can anyone see what I may be doing wrong?
0
c0mrad
Asked:
c0mrad
1 Solution
 
leakim971PluritechnicianCommented:
in the mongo console what do you get with the following :

db.mycollection.find({log:{$lt:ISODate('2013-06-01T00:23:24.154Z')}}, {_id:1}).length;

Open in new window

0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Tackle projects and never again get stuck behind a technical roadblock.
Join Now