Swapnil Sonawane
Swapnil Sonawane

Reputation: 1455

Mongo group query does not used indexes or slow down queries

I have used mongodb 1.8.1. In which I have collection which contains more than 1.8 million records. In this collections all records are simple object means not nested objects or array

Like as follows

{ name : "xyz" , "id" : 123 ,"a" : "na" , "c" : "in" , "cmp" : "pq" , "ttl" : "sd"}

All records are like this.

On this collections at time more 5 queries fire in which 2 is simple queries one contains exists in it and another one is simple query which uses index properly.

Another 2 are group queries which in which condition fields are in indexes and one contains exists.

Another one 1 distinct query with proper condition which is also index.

And order of query fire is first qroup queries then 1 simple query then distinct query and last simple query.

So data loads slowly.

If such 2 -3 calls make then it loads very lowly sometimes gives error read time out.

The collections have more than 1 index.

Upvotes: 1

Views: 597

Answers (1)

Remon van Vliet
Remon van Vliet

Reputation: 18625

$exists queries do not use indexes (fixed from 1.9.1 onwards)

group commands use the JS context of mongodb which is exclusively locked while it's being used. This will affect performance of concurrent group queries. A new aggregation framework is under development that should help with this (2.1 onwards). Monitor https://jira.mongodb.org/browse/SERVER-447 for progress. In my experience it's usually more performant to do "group" like aggregation app-side.

Upvotes: 1

Related Questions