lundi 9 février 2015

Mongo find query is not using indexes in java code but working on mongo cosole


I found a strange issue. When i run mongo query from my java code with explain true it does not show me index used in the query but when i run it using mongo console it works fine .



db.locationCount.find({ "articleId" : "3784416" , "host" : "abc.com" , "timeStamp" : 1423481400000 , "isIndia" : -1 , "location" : "Unresolved"}).explain();


On console it gives



{
"cursor" : "BtreeCursor articleId_1_host_1_timeStamp_1_isIndia_1_location_1",
"isMultiKey" : false,
"n" : 1,
"nscannedObjects" : 1,
"nscanned" : 1,
"nscannedObjectsAllPlans" : 5,
"nscannedAllPlans" : 7,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 1,
"indexBounds" : {
"articleId" : [
[
"3784416",
"3784416"
]
],
"host" : [
[
"abc.com",
"abc.com"
]
],
"timeStamp" : [
[
1423481400000,
1423481400000
]
],
"isIndia" : [
[
-1,
-1
]
],
"location" : [
[
"Unresolved",
"Unresolved"
]
]
},
"server" : "ibeatdb61:27017",
"filterSet" : false,
"millis" : 1
}


But on java console it shows this



{ "cursor" : "BasicCursor" , "isMultiKey" : false , "n" : 1002492 , "nscannedObjects" : 1002492 , "nscanned" : 1002492 , "nscannedObjectsAllPlans" : 1002492 , "nscannedAllPlans" : 1002492 , "scanAndOrder" : false , "indexOnly" : false , "nYields" : 7831 , "nChunkSkips" : 0 , "millis" : 499 , "allPlans" : [ { "cursor" : "BasicCursor" , "isMultiKey" : false , "n" : 1002492 , "nscannedObjects" : 1002492 , "nscanned" : 1002492 , "scanAndOrder" : false , "indexOnly" : false , "nChunkSkips" : 0}] , "server" : "ibeatdb61:27017" , "filterSet" : false , "stats" : { "type" : "COLLSCAN" , "works" : 1002494 , "yields" : 7831 , "unyields" : 7831 , "invalidates" : 0 , "advanced" : 1002492 , "needTime" : 1 , "needFetch" : 0 , "isEOF" : 1 , "docsTested" : 1002492 , "children" : [ ]}}


MOngo version is 2.6.4 and jar version is 2.12.0





Aucun commentaire:

Enregistrer un commentaire