javascript - 如何过滤取自 $lookup 的数据
问题描述
我目前正在尝试通过使用获取的数据过滤它们来聚合文档列表$lookup
Product.aggregate([
{
$lookup: {
from: "categories",
localField: "category",
foreignField: "_id",
as: "category",
},
},
{ $unwind: "$category" }])
我希望添加{ $match: { "category.left": {$gte: 3}} },
能够获得left
属性大于指定类别的所有产品,但到目前为止我什么也没得到。解决方案是什么?
分类文件
{ "_id" : ObjectId("570557d4094a4514fc1291d6"), "left" : 1, "right" : "2" }
{ "_id" : ObjectId("570557d4094a4514fc1291d7"), "left" : 3, "right" : "8"}
{ "_id" : ObjectId("570557d4094a4514fc1291d8"), "left" : 4, "right" : "5"}
{ "_id" : ObjectId("570557d4094a4514fc1291d9"), "left" : 6, "right" : "7" }
产品文件
{ "_id" : ObjectId("570557d4094a4514fc129120"), "category": ObjectId("570557d4094a4514fc1291d6") }
{ "_id" : ObjectId("570557d4094a4514fc129121"), "category": ObjectId("570557d4094a4514fc1291d7")}
{ "_id" : ObjectId("570557d4094a4514fc129122"), "category": ObjectId("570557d4094a4514fc1291d8")}
{ "_id" : ObjectId("570557d4094a4514fc129123"), "category": ObjectId("570557d4094a4514fc1291d9") }
我期待得到
{ "_id" : ObjectId("570557d4094a4514fc129121"), "category": ObjectId("570557d4094a4514fc1291d7")}
{ "_id" : ObjectId("570557d4094a4514fc129122"), "category": ObjectId("570557d4094a4514fc1291d8")}
{ "_id" : ObjectId("570557d4094a4514fc129123"), "category": ObjectId("570557d4094a4514fc1291d9") }
对于我的回应
解决方案
推荐阅读
- python - Pandas - 执行多列的转置
- javascript - 修复未定义标签错误 - Javascript
- php - HTML 表单未使用 post/get 方法提交输入值
- eclipse - 在eclipse中导入项目与通过git克隆然后在eclipse中打开的区别
- apollo - 响应不成功:使用 `datasources` 时收到状态码 500
- reactjs - React:如何在映射中根据状态计数器分配键和增加状态计数器?
- c++ - 在我的项目中创建对象数组的问题:预期的 unqualified-id
- python - Tkinter 在一个框架中创建多个按钮
- elasticsearch - fscrawler 容器不健康(退出代码 126)
- c++ - C++ 实现抽象类