我是mongodb的新手。我创建了一个查询,用于从我的集合中获取数据,但这个数据太贵了。
我的收藏
{
"_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
}
查询
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}}}]
}}])
此查询太贵了。如何提高性能? 申请后退,收藏量很大。
我的收藏明细
我的收藏有超过800万条记录。每条记录包含嵌入式记录“job_details”,每个嵌入式记录包含超过10万个数据(用户详细信息)。
我需要上述查询的结果。使用该查询一切都很好,但这太贵了。 Job_details字段包含用户应用的作业作业的详细信息。如何提高绩效?
我已准备好更改我的收藏记录格式。
我的要求是使用owner_id(job_id)获取他为特定作业ID搜索应用的所有用户详细信息(限制和偏移)。
需要的数据:
facet计为9个字段
例如:字段“status”:[{“0”:10},“1”:12](在过滤后的数据中,10个人的状态为“0”,12个人的状态为“1”,例如:2个字段“city_name”12个人在“班加罗尔”中,'hydrabad'中有20个人
和总数(申请该特定工作的用户数)和doc:25条记录
这是我的查询的输出
{
"status": [
{_id:"1",count:1},
{_id:"2",count:2}
],
"course_name": [
{_id:"B.Com",count:1},
{_id:"12th Pass (HSE)",count:1},
{_id:"BE/B.Tech",count:1}
],
"branch_name": [
{_id:"12thpass",count:1},
{_id:"Food Technology",count:1},
{_id:"Commerce",count:1}
],
"doc": [
{
"10": 10,
"12": 12,
"last_name": "Chandr",
"university_name": "Deemed (Autonomus) University",
"xiith_mark": 65,
"id": "3538272",
"first_name": "Purna",
"course_name": "BE/B.Tech",
"institute_name_string": "College of Engineering, Shri Mata Vaishno Devi University, Udhampur",
"profile_percentage": 55,
"xiith_mark_type": "Percentage",
"xth_mark_type": "Percentage",
"candidate_sublocation_name_string": "Chembur ",
"date_of_birth": "03-June-1977",
"xth_mark": 56,
"last_login": 1448444535,
"percentage": 65,
"job_details": {
"status": 2,
"applied_date": 1444716448,
"contact_viwed_status": null,
"label_name": [],
"questionnaire_status": 0,
"batch_id": null,
"owner_type": "jobs",
"call_letter": 119,
"owner_id": 91493
},
"branch_name": "Food Technology",
"candidate_state_name": "Maharashtra",
"candidate_city_name_string": "Mumbai",
"gender": "Male",
"fw_id": "FW15883617",
"cgpa": 0,
"picture_path": "",
"hq_passout_year": 2003,
"candidate_sublocation_name": "Chembur "
},
{
"10": 10,
"12": 12,
"last_name": "",
"xiith_mark": 0,
"id": "3538066",
"first_name": "Liji",
"last_login": 1434982626,
"course_name": "B.Com",
"profile_percentage": 28,
"xiith_mark_type": "Percentage",
"xth_mark_type": "Percentage",
"date_of_birth": "01-January-1970",
"xth_mark": 0,
"candidate_state_name": "Gujarat",
"percentage": 78,
"job_details": {
"status": 2,
"applied_date": 1444368899,
"contact_viwed_status": 0,
"label_name": [],
"questionnaire_status": 1,
"batch_id": null,
"owner_type": "jobs",
"call_letter": null,
"owner_id": 91493
},
"branch_name": "Commerce",
"candidate_city_name_string": "Ahmedabad",
"gender": "",
"fw_id": "FW15883411",
"cgpa": 0,
"picture_path": "",
"hq_passout_year": 2003
},
{
"10": 10,
"12": 12,
"last_name": "Xth",
"job_483": 1,
"xiith_mark": 67,
"id": "3538273",
"first_name": "Purnax",
"last_login": 1444210762,
"course_name": "12th Pass (HSE)",
"profile_percentage": 55,
"xiith_mark_type": "Percentage",
"xth_mark_type": "Percentage",
"candidate_sublocation_name_string": "Bibvewadi ",
"date_of_birth": "04-June-1956",
"xth_mark": 76,
"candidate_state_name": "Maharashtra",
"percentage": 0,
"job_details": {
"status": 1,
"applied_date": 1444716448,
"contact_viwed_status": 0,
"label_name": [],
"questionnaire_status": 0,
"batch_id": null,
"owner_type": "jobs",
"call_letter": null,
"owner_id": 91493
},
"branch_name": "12thpass",
"candidate_city_name_string": "Pune",
"gender": "Male",
"fw_id": "FW15883618",
"cgpa": 0,
"picture_path": "",
"hq_passout_year": 0,
"candidate_sublocation_name": "Bibvewadi "
}
],
"candidate_sublocation_name_string": [
{_id:"Bibvewadi",count:2},
{_id:"Chembur",count:1}
],
"contact_viwed_status": [
{_id:"0",count:2},
{_id:"1",count:1}
],
"label_name": [],
"questionnaire_status": [
{_id:"0",count:2},
{_id:"1",count:1}
],
"total_count": [
{_id:null,count:3}
],
"skill": [
{_id:"None",count:3}
],
"candidate_city_name_string": [
{_id:"Pune",count:2},
{_id:"Ahmedabad",count:1}
],
"hq_passout_year": [
{_id:"2014",count:1},
{_id:"2011",count:1},
{_id:"1999",count:1}
]
}