T
T
TheInsable2017-01-05 23:42:30
MongoDB
TheInsable, 2017-01-05 23:42:30

Why is mongodb slow when searching?

There is a collection, it has a little more than 21 million documents, some documents have a field: true, the rest do not have this field at all.
db.collection.find({"field": {$ne: true}}).count()
It always takes from 14 seconds, such documents are 18.5KK. An index on this field has been created, in total, documents in this collection have 4 fields, indexes for each.
Is there any way to increase the speed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2017-01-05
@TheInsable

indexes on true/false are not effective in any bases, it is easier to transfer them to a separate collection.
it is quite possible that the search does not go by the index (but a full enumeration), for the index you need to fill in the field and search for false.
You can also try $exists: false

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question