0
我有以下的文檔結構獲取子集的匹配子集,並計數MongoDB中
{
"_id" : ObjectId("578a14112acb483c1a0dce0a"),
"professionalInterests" : [
{
"_id" : ObjectId("578a063a0068ec0c1320a1de"),
"interestName" : "Finance and Accounting"
},
{
"_id" : ObjectId("578a063a0068ec0c1320a1e7"),
"interestName" : "Journalism and Mass Media"
},
{
"_id" : ObjectId("578a063a0068ec0c1320a1e5"),
"interestName" : "Manufacturing Industry"
}
],
"personalInterests" : [
{
"_id" : ObjectId("578a063a0068ec0c1320a1d2"),
"interestName" : "Music"
},
{
"_id" : ObjectId("578a063a0068ec0c1320a1d4"),
"interestName" : "Sports"
}
]
}
和我有一些利益陣列狀
var professionalInterests = [
{
"interestName" : "Finance and Accounting"
}
];
var personalInterests = [
{
"interestName" : "Music"
}
];
我想要檢索的所有文件,但通過匹配的排序「專業興趣「和」專業興趣「。 我試過$setIntersection
但它不適合我。 我也試過通過$unwind
,$project
,$size
但它不是有效的解決方案。 導致文件應包含但排序取決於匹配的利息(如果與「用戶A」 2個利益一致和「用戶B」 3個利益則匹配的「用戶B」是像上面列表中,則「用戶A」。
{
professionalInterests : [],//user professional interests
personalInterests : [],//user personal interest
matchedProfessionalInterests : [],// contain the matched professional interest
matchedPersonalInterests : [],// contain the matched personal interest
matchedProfessionalInterestsCount : number,
matchedPersonalInterests : number
}
你可以舉一個你希望得到的數據的例子嗎? –
@AndriySimonov更新。 –