SolvedPrivate

MongoDB Record Delete using JavaScript

Posted on 2013-12-17
1
64 Views
Last Modified: 2016-02-10
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
Comment
Question by:c0mrad
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39726424
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes some very basic things about SQL Server filegroups.
Read about achieving the basic levels of HRIS security in the workplace.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question