I have 19 Million records in my mongo collection. Format of my collection is:
{
"_id" : ObjectId("5992d5a5e7f31a5e90abb881"),
"_class" : "com.abc.Try",
"field1_code" : "mycode_sdsvmnsbd7986fskljfnsv89s7fmnslfsd78",
"field2_id" : "5992d5a5e7f31a5e90abb87e",
"field3_id" : NumberLong(1681703),
"field4_id" : NumberLong(40119344),
"field5_create_date" : ISODate("2015-05-15T09:17:46.000Z"),
"field6_update_date" : ISODate("2015-05-31T08:53:59.000Z"),
"field7_status" : "active",
"field8_status" : "active"
}
I am using Spring batch : org.springframework.batch.item.ItemReader<MyCollection>
to read my collection but its reading is quite slow. So I created a new index using command:
db.monitoring_profile.createIndex({ field7_status: 1, field8_status: 1, field4_id: 1})
Still its slow. Please suggest. I believe its an issue of mongodb indexing.
My Mongo Query is :
{'field7_status': 'active', 'field8_status' : 'active', 'field4_id': { $in: [.... 10000 values....] }}
My Explain query result is:
db.coll.find({'field7_status': 'active', 'field8_status' : 'active', 'field4_id': { $in: [40009361, 40006884] }}).explain()
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "mycollection.coll",
"indexFilterSet" : false,
"parsedQuery" : {
"$and" : [
{
"field7_status" : {
"$eq" : "active"
}
},
{
"field8_status" : {
"$eq" : "active"
}
},
{
"field4_id" : {
"$in" : [
40006884.0,
40009361.0
]
}
}
]
},
"winningPlan" : {
"stage" : "EOF"
},
"rejectedPlans" : []
},
"serverInfo" : {
"host" : ".......",
"port" : 27017,
"version" : "3.4.2",
"gitVersion" : "........"
},
"ok" : 1.0
}