0

I have in my mongoDB more than 50000 entries with an ID (in one collection).

I would like to get only the ID (and not the other infos).

In server.js, I connect to mongoDB via mongoose:

mongoose.connect('mongodb://10.3.5.12/mydb');

I need to iterate all the 50 000 entries to check the ID, check the duplicates and store in a list.

Do I need to create a controller? It will be very heavy with 50 000 entries? Any idea how I can proceed?

var listId= [];
...
listId.push(id);

[EDIT] Could I try something like that with mongoose?

    MyModel.find().distinct('id', function(error, id) {
        // ids is an array of all ObjectIds
       var listId= [];
       ...
       listId.push(id);
    });

Thanks for your help!

6
  • 1
    What do you mean by "check the double one"? Commented Oct 9, 2014 at 16:44
  • Sorry, I mean duplicates. Commented Oct 9, 2014 at 16:51
  • So you're basically trying to get all id's in the database, removing all duplicates? Commented Oct 9, 2014 at 16:56
  • check mapreduce : glassonionblog.wordpress.com/2012/03/19/… Commented Oct 9, 2014 at 17:01
  • 1
    @Jose Have you checked mapReduce? Commented Apr 6, 2015 at 8:38

1 Answer 1

1

If you're using Mongoose 3.x+ you can do this:

MyModel.find().distinct('_id', function(error, ids) {
    // ids is an array of all ObjectIds
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.