SolvedPrivate

MongoDB Record Delete using JavaScript

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now