0
我是使用MongoDB的新手。
我的文檔這樣一個集合:獲取方面數和數據時的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
}
我需要從這個分貝數方面查找數據。
需要小計數以下字段
- job_details.status,job_details.label_name, job_details.contact_viwed_status,candidate_city_name_string,
課程名稱,hq_passout_year,branch_name, candidate_sublocation_name_string,技能
而且總匹配數和限制數據
我爲每個小面和單獨的查詢爲總計數一個查詢和用於數據
一個查詢共有9 + 1 + 1 = 11個querys
Query的是
面查詢對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個Querys 所以性能是非常非常低。有可能使這個查詢單個查詢或我如何提高性能。
請幫忙。
你在問$ facet嗎? (https://jira.mongodb.org/browse/SERVER-23654) –
是的。我需要facet計數,總數和數據 – SuFi
當我使用$ fecet agot錯誤。無法識別的流水線階段名稱:'$ facet', – SuFi