** UPDATE **
I sent a response as it was confirmed as a problem.
** ORIGINAL **
First off, I'm sorry - I just started using MongoDB yesterday, and I'm still pretty new to this. I have a fairly simple query, and using PHP, my conclusions are as follows:
Mongo version 2.0.4 running on CentOS 6.2 (Final) x64
$start = microtime(true);
$totalactive = $db->people->count(array('items'=> array('$gt' => 1)));
$end = microtime(true);
printf("Query lasted %.2f seconds\n", $end - $start);
No index returns:
Query lasted 0.15 seconds
I have 280,000 entries in the database. So I thought adding an index to the "elements" should be useful because I often request this data. But, to my disbelief, after adding the index, I get the following:
Query lasted 0.25 seconds
Am I doing something wrong?
Instead of count, I used find to get an explanation, and this is the result:
> db.people.find({ 'items' : { '$gte' : 1 } }).explain();
{
"cursor" : "BtreeCursor items_1",
"nscanned" : 206396,
"nscannedObjects" : 206396,
"n" : 206396,
"millis" : 269,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"items" : [
[
1,
1.7976931348623157e+308
]
]
}
}
If I change my request to "$ ne" 0, it will take another 10 m!
:
> db.people.stats()
{
"ns" : "stats.people",
"count" : 281207,
"size" : 23621416,
"avgObjSize" : 84.00009957077881,
"storageSize" : 33333248,
"numExtents" : 8,
"nindexes" : 2,
"lastExtentSize" : 12083200,
"paddingFactor" : 1,
"flags" : 0,
"totalIndexSize" : 21412944,
"indexSizes" : {
"_id_" : 14324352,
"items_1" : 7088592
},
"ok" : 1
}
1 , , .
, :
> db.people.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "stats.people",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"items" : 1
},
"ns" : "stats.people",
"name" : "items_1"
}
]