only return document _id on mongoose .find()

Viewed 9161

I update 100's of documents every second by pushing new data to an array in its document. To get the document of which I am going to add data to, I use the mongoose .find().limit(1) function, and return the whole document. It works fine.

To help with some memory and cpu issues I have, I was wondering how I could get find() to only return the id of the document so I can use that to $push or $set new data.

Thanks.

3 Answers

You could use the distinct method in order to get an array of _id for your query.

Follow this question

As mentioned by @alexmac, this works for me:

collection.find({}, '_id')
Related