Dear all
I have collection Devices with data sample below.
db.Devices.find()
{
"_id" : NumberLong(1),
"CapturedDate" : [
[
1,
ISODate("2012-05-10T02:07:50.159Z")
],
[
2,
ISODate("2012-05-09T12:31:50.299Z")
]
],
"OSName" : "Windows",
"DeviceType" : "Mobile"
}
{
"_id" : NumberLong(2),
"CapturedDate" : [
[
1,
ISODate("2012-04-10T06:59:50.123Z")
],
[
3,
ISODate("2012-12-09T12:06:50.243Z")
]
],
"OSName" : "Iphone",
"DeviceType" : "Mobile"
}
I want to find size of "CapturedDate" great than 2, and this query run slowly. I try to create index on "CapturedDate" but performance not improve. Please give me to your suggestion to solute this trouble.
db.Devices.ensureIndex( { CapturedDate : 1 } )
db.Devices.find({"CapturedDate":{$size:2}},{CapturedDate:1}).explain()
{
"cursor" : "BasicCursor",
"nscanned" : 1218300,
"nscannedObjects" : 1218300,
"n" : 73,
"millis" : 21544,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
}
}
>
> db.Devices.find( { $where: "this.CapturedDate.length > 1" } ).hint({CapturedDate : 1}).explain()
{
"cursor" : "BtreeCursor CapturedDate_1",
"nscanned" : 1218376,
"nscannedObjects" : 1218376,
"n" : 73,
"millis" : 23276,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : true,
"indexOnly" : false,
"indexBounds" : {
"CapturedDate" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
]
}
Thanks and Regards
Tom Vo