我愿意在这个系列中应用$ filter来获得#34; Applied Mathematics"结果只在数组中。我正在提供像这样[" Applied Mathematics"]的数组形式的输入到下面的集合。
$filter: {
input: "$univisorEducation",
as: "univisorEducation",
cond: {
$setIsSubset: ["$$univisorEducation.course", courses]
}
}
为此我在$ project中使用$ filter,下面是我的$ filter代码
{ "_id" : ObjectId("58a95d81eead32e82932b535"), "univisorEducation" : [ ] }
{
"_id" : ObjectId("58a9643deead32e82932b54b"),
"univisorEducation" : [
{
"educationLevel" : "MASTER",
"courseType" : "GRADUATE",
"year" : 2020,
"college" : ObjectId("58a936afd48f2b502858b9f7"),
"_id" : ObjectId("58a96495eead32e82932b54f"),
"course" : [
"Applied Mathematics"
]
}
]
}
问题是我只得到了这个结果
<android.support.v7.widget.Toolbar
android:id="@+id/videos_toolbar"
style="@style/ToolBarTextStyle"
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
android:layout_alignParentTop="true"
android:background="@color/ToolBarColor"
android:paddingRight="@dimen/_32sdp"
android:textAlignment="center"
app:titleTextColor="@color/ThemeColor">
&#34; _id&#34; :ObjectId(&#34; 58a95d81eead32e82932b535&#34;)应该有应用数学的结果。
答案 0 :(得分:1)
将您的$filter
汇总更改为以下内容。
将courses
数组与univisorEducation.course
进行比较,如果匹配univisorEducation.course
则返回true,否则返回false。
$filter: {
input: "$univisorEducation",
as: "univisorEducation",
cond: {
$ne:[{$setIntersection: [courses, "$$univisorEducation.course" ]}, []]
}
}