For example, I have inserted 10K documents in collection:
for ($i = 0; $i < 100; ++$i) {
for ($j = 0; $j < 100; ++$j) {
$collection->insert(array('i' => $i, 'j' => $j));
}
}
I have created Indexes:
pkrs:PRIMARY> db.testTest.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "parts.testTest",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"i" : 1,
"j" : 1
},
"ns" : "parts.testTest",
"name" : "i_1_j_1"
}
]
Then I want to fetch 600 documents with 'OR' condition:
for ($i = 5; $i < 12; ++$i) {
for ($j = 0; $j < 100; ++$j) {
$orArr[] = array('i'=>$i, 'j' => $j);
}
}
$cursor = $collection->find(array('$or' => $orArr));
$cursor->batchSize(1000);
foreach ($cursor as $doc) {
// code
}
And first document fetches about 1.5 second! :( How can I improve performance?