[英]mongodb performance issue when fetching facet count and data
我是使用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
}
我需要從數據庫中獲取包含facet count的數據。
需要以下方面的構面計數
並且總匹配數和數據有限制
我對每個方面進行了單獨的查詢,對總數進行了一個查詢,對數據進行了一個查詢
總計9 + 1 + 1 = 11個查詢
查詢的是
job_details.status和job_details.label_name和job_details.contact_viwed_status的方面查詢都像這樣
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 }} }
])
其他6個方面的查詢是這樣的
db.Response.aggregate([ {"$and":[{"job_details.owner_id" : 428},{"job_details.owner_type" : 'searches'}]},
{"$group": {"_id":"$candidate_city_name_string","count": {"$sum": 1 }}}] )
查詢收集數據
db.Response.aggregate([
{"$and":[{"job_details.owner_id" : 428}{"job_details.owner_type" : 'searches'}]},
{"$limit":25},``
{ "$skip":0} ,
{"$unwind":"$job_details"}])
查詢收集總數
db.Response.find({"$and":[{"job_details.owner_id" : 428},{"job_details.owner_type" : 'searches'}]}).count()
總共3 + 9 + 1 + 1 = 11條查詢因此性能非常低。 可以使這11個查詢變為單個查詢,或者如何提高性能。
請幫忙。
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}}}]
}}])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.