gpt4 book ai didi

mongodb - 蒙戈数据库 : $lookup (aggregation)/join with two different data types

转载 作者:行者123 更新时间:2023-12-03 02:59:33 26 4
gpt4 key购买 nike

我正在尝试使用 mongo 3.4 $lookup:function

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

orders:
{ "_id" : 1, "itemid" : "1234", "price" : 12, "quantity" : 2 }

invdentory :
{ "_id" : 1, "skuid" : 123, description: "product 1", "instock" : 120 }

这里的问题是要连接的字段是字符串和整数。我怎样才能在 mongo 中进行此查找

最佳答案

无法更改聚合管道的 $lookup 步骤内的数据类型。该主题已经在这里讨论过:

在两个线程中,最终的解决方案是:您必须事先以编程方式转换数据类型

关于mongodb - 蒙戈数据库 : $lookup (aggregation)/join with two different data types,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44570662/

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