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更新。 –