Reputation: 183
Does mongoose store data in such a way that it's more efficient to find an object using its id than using other parameters? (such as storing objects in ascending order of their ids so that binary search can be used)
Upvotes: 0
Views: 49
Reputation: 68
It is not mongoose which maintains objectId, but MongoDB manages it internally.
MongoDB by default adds objectId to all the collections if not specified and also adds an index on this objectId by default. This index on objectId makes it easier to retrieve documents if searched on objectId.
However, if you want to search on other fields then you can create indexes of your own on those fields.
Upvotes: 1