嗨,我有以下mongo agrgegate查询
我正在尝试转换此usin mongo驱动程序
db.SampleDb.aggregate([{
$match: {
_id: new ObjectId(secId),
"visible": true
}
}, {
$unwind: "$ddFields"
}, {
$match: {
"ddFields.mmList": {
$exists: true
}
}
}, {
$lookup: {
from: "mmList",
localField: "ddFields.mmList.id",
foreignField: "mmListId",
as: "mmList_lookup"
}
}, {
$project: {
fieldId: "$ddFields.fId",
mmList_lookup: {
$filter: {
input: "$mmList_lookup",
as: "mmList_lookup",
cond: {
$eq: ["$$mmrList_lookup.sId", new ObjectId(sId)]
}
}
}
}
}, {
$unwind: "$mmList_lookup"
},
{
$project: {
_id: 0,
secId: "$_id",
fId: "$fieldId",
mmListId: "$mmList_lookup.mmListId",
refId: "$mList_lookup.refId",
mmValues: {
$filter: {
input: "$mmList_lookup.mmValues",
as: "mmValue",
cond: {
"$setIsSubset": [["$fId"], "$$mmValue.selected"]
}
}
}
}
}
]);
我写了以下
BasicDBList bb = new BasicDBList();
basicDBList.add("$fId");
BasicDBList basicDBList1 = new BasicDBList();
basicDBList.add("bb");
basicDBList.add("$$mmValue.assigned");
AggregateIterable<Document> output = collection.aggregate(Arrays.asList(
new Document("$match", new Document("_id", secId)
.append("visible",true)),
new Document("$unwind", "$ddFields"),
new Document("$match", new Document("ddFields.mmList", new Document("$exists",true))),
new Document("$lookup",
new Document("from", "mmLists")
.append("localField", "ddFields.mmList.id")
.append("foreignField", "mmListId")
.append("as", "mmList_lookup")),
new Document("$project",
new Document( "fid", "$ddFields.fid")
.append("mmList_lookup",new Document("$filter",
new Document("input","$mmList_lookup")
.append("as","mmList_lookup")
.append("cond",new Document("$eq",basicDBList))))),
new Document("$unwind", "$mmList_lookup"),
new Document("$project",new Document("secId","$_id")
.append("fid","$fid")
.append("mmListId","$mmList_lookup.mmListId")
.append("refId","$mmList_lookup.refId")
.append("mmValues",new Document("$filter",
new Document("input","$mmList_lookup.mmValues")
.append("as","mmValue")
.append("cond",new Document("$setIsSubset",basicDBList1)
)))
)
));
我收到错误消息:“在服务器上使用'未定义的变量:mmValue' 以类似的方式完成此查询中使用的第一个投影的效果如何。 我不明白我在想什么
不确定如何显示未定义的变量