gpt4 book ai didi

java - Mongodb $lookup 查询获取别名为空白

转载 作者:太空宇宙 更新时间:2023-11-04 09:20:11 25 4
gpt4 key购买 nike

db.ticket.aggregate([
{
$lookup: {
from: "crmorder",
localField: "subOrderId",
foreignField: "currentStatus",
as: "comments"
}
}
])

结果评论字段为什么变成空白?

最佳答案

您还有一张名为 crmorder 的表

工单表中必须有 - subOrderId 字段

在 crmorder 表中必须有 - currentStatus 字段

还有工单表 subOrderId 字段 == crmorder 表 currentStatus 字段

这里是示例片段:

db.orders.insert([
{ "_id" : 1, "item" : "almonds", "price" : 12, "quantity" : 2 },
{ "_id" : 2, "item" : "pecans", "price" : 20, "quantity" : 1 },
{ "_id" : 3 }
])

db.inventory.insert([
{ "_id" : 1, "sku" : "almonds", description: "product 1", "instock" : 120 },
{ "_id" : 2, "sku" : "bread", description: "product 2", "instock" : 80 },
{ "_id" : 3, "sku" : "cashews", description: "product 3", "instock" : 60 },
{ "_id" : 4, "sku" : "pecans", description: "product 4", "instock" : 70 },
{ "_id" : 5, "sku": null, description: "Incomplete" },
{ "_id" : 6 }
])

db.orders.aggregate([
{
$lookup:
{
from: "inventory",
localField: "item",
foreignField: "sku",
as: "inventory_docs"
}
}
])

关于java - Mongodb $lookup 查询获取别名为空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58407945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com