How fast is it to search for ObjectId in Mongodb?

I am looking for ObjectIds everywhere, as if they were cakes.

This is normal? _id fields should appear crazy, shouldn't they?

+4
source share
4 answers

_id is the primary key. It is indexed. Of course it's fast.

+2
source

A more accurate answer: MongoDB uses B-Tree indexes. Finding a specific value in a B-Tree has O (log n) complexity in the average and worst case, which can be considered quite fast (i.e. Binary search). This is not constant complexity = O (1), although you can still have some slowdown effects if the index size becomes larger than the available RAM. (MongoDB tries to store indexes in RAM, and every IO needed to find an index on disk will significantly slow down your query).

+6
source

The pointer to the _id field is automatically created by mongo and the default primary key. Speedwise, it will be very quick to access documents using the _id field.

What do you have?

0
source

ObjectIds , if your main data access method will be the fastest way to extract your material from MongoDB. We use our MongoDB as a keystore for most of our data access. You will have great results doing what you do.

0
source

All Articles