P
P
PetrW2017-07-17 10:54:06
MongoDB
PetrW, 2017-07-17 10:54:06

Why does count take a long time in mongo on a field with an index?

Initial data:
Collection of 2,000,000 records
Unit field has an index
{"unit" : 1.0}
 Problem:
Query

db.getCollection('CollectionName').find({"unit":"value"}).count()

runs for 5 seconds, returns a value of 200,000 records.
A request
db.getCollection('CollectionName').find({"unit":"value"})

takes 0.005 seconds.
Why does a query with count take so long?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question