SolvedPrivate

MongoDB Record Delete using JavaScript

Posted on 2013-12-17
1
67 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
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…

726 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