Reputation: 1925
Is there a direct mapping for the (default) _id in mongodb ??
db.model.findById({_id:xxxxxxxxxxxx})
or when we put a search based on the _id like the above one...it goes on kind of searching in the database for _id ?
In other words does the above query takes only 1 unit of time or it takes n units of time depending on the size of database
Upvotes: 0
Views: 71
Reputation: 497
It depends on whether the field is indexed or not. If you have an index (like in the case of _id) the access time depends on the size of the database in term of O(logN). Without index it would be O(n).
More info: MongoDB Index Complexity
Upvotes: 1