mongodb performance issue when fetching facet count and data -
i'm new using mongodb.
have collection of documents this:
{ "_id" : objectid("58204f60536d1a27736d512b"), "last_name" : "vinaykumar", "university_name" : "osmania university", "job_483" : 1, "xiith_mark" : 0, "id" : "3305775", "first_name" : "v", "course_name" : "diploma", "institute_name_string" : "govt.polytechnic,kothagudem", "profile_percentage" : 60, "xiith_mark_type" : "percentage", "xth_mark_type" : "percentage", "date_of_birth" : "11-march-1995", "xth_mark" : 0, "last_login" : 1379565790, "percentage" : 76, "job_details" : [ { "status" : numberlong(0), "applied_date" : numberlong(1476703354), "contact_viwed_status" : 0, "label_name" : [ ], "questionnaire_status" : 0, "batch_id" : null, "owner_type" : "searches", "call_letter" : null, "owner_id" : numberlong(465) }, { "status" : numberlong(0), "applied_date" : numberlong(1477051963), "contact_viwed_status" : 0, "label_name" : [ ], "questionnaire_status" : 0, "batch_id" : null, "owner_type" : "searches", "call_letter" : null, "owner_id" : numberlong(482) }, { "status" : numberlong(0), "applied_date" : numberlong(1477052973), "contact_viwed_status" : 0, "label_name" : [ ], "questionnaire_status" : 0, "batch_id" : null, "owner_type" : "searches", "call_letter" : null, "owner_id" : numberlong(483) } ], "branch_name" : "electrical & electronics", "candidate_state_name" : "andhra pradesh", "candidate_city_name_string" : "andhra pradesh-other", "10" : 10, "12" : 12, "gender" : "male", "fw_id" : "fw15651132", "cgpa" : 0, "picture_path" : "", "hq_passout_year" : 2013 }
i need find data db facet count .
need facet count following fields
- job_details.status , job_details.label_name, job_details.contact_viwed_status, candidate_city_name_string,
course_name, hq_passout_year, branch_name , candidate_sublocation_name_string , skill
and total matching count , data limit
i did separate query each facet , 1 query total count , 1 query data
total 9+1+1=11 querys
query's are
facet query's job_details.status , job_details.label_name , job_details.contact_viwed_status did
db.response.aggregate([ {"$match":{"$and":[{"job_details.owner_id" : 428}, {"job_details.owner_type" : 'searches'}]}}, {"$unwind": "$job_details" }, {"$group": {"_id":"$job_details.status","count": {"$sum": 1 }} } ])
other 6 facet query's this
db.response.aggregate([ {"$and":[{"job_details.owner_id" : 428},{"job_details.owner_type" : 'searches'}]}, {"$group": {"_id":"$candidate_city_name_string","count": {"$sum": 1 }}}] )
query collecting data
db.response.aggregate([ {"$and":[{"job_details.owner_id" : 428}{"job_details.owner_type" : 'searches'}]}, {"$limit":25},`` { "$skip":0} , {"$unwind":"$job_details"}])
query collecting total count
db.response.find({"$and":[{"job_details.owner_id" : 428},{"job_details.owner_type" : 'searches'}]}).count()
total 3+9+1+1=11 querys performance very low . possible make 11 query single query or how can improve performance.
please help.
db.response.aggregate([ {"$match":{"$and":[{"job_details.owner_id" : 482},{"job_details.owner_type" : 'searches'}]}}, {$facet: { "status": [ {"$unwind": "$job_details" }, {"$group": {"_id":"$job_details.status","count": {"$sum": 1 }} } ], "label_name": [ {"$unwind": "$job_details" }, {"$unwind": "$job_details.label_name" }, {"$group": {"_id":"$job_details.label_name","count": {"$sum": 1 }} } ] , "contact_viwed_status": [ {"$unwind": "$job_details" }, {"$group": {"_id":"$job_details.contact_viwed_status","count": {"$sum": 1 }} } ], "questionnaire_status": [ {"$unwind": "$job_details" }, {"$group": {"_id":"$job_details.questionnaire_status","count": {"$sum": 1 }} } ], "candidate_city_name_string": [ {"$group": {"_id":"$candidate_city_name_string","count": {"$sum": 1 }}} ], "course_name": [ {"$group": {"_id":"$course_name","count": {"$sum": 1 }}} ], "hq_passout_year": [ {"$group": {"_id":"$hq_passout_year","count": {"$sum": 1 }}} ], "branch_name": [ {"$group": {"_id":"$branch_name","count": {"$sum": 1 }}} ], "candidate_sublocation_name_string": [ {"$group": {"_id":"$candidate_sublocation_name_string","count": {"$sum": 1 }}} ], "skill": [ {"$group": {"_id":"$skill","count": {"$sum": 1 }}} ], "doc": [ {"$limit":25}, {"$skip":0}, {"$unwind":"$job_details"}], "total_count":[ {"$group":{"_id": "null", "count":{"$sum":1}}}] }}])
Comments
Post a Comment