【发布时间】:2020-03-01 18:44:44
【问题描述】:
如何在mongodb聚合期间将字符串转换为int类型?
{ $lookup:{ from: 'circle', localField:'circle_id', foreignField: 'circle_id', as: 'circleDetail' } },
localField: 'circle_id' -> int 类型
foreignField: 'circle_id' -> 字符串类型
我想将外部字段转换为int类型。
【问题讨论】:
-
您将“circle_id”存储在哪个变量中?
-
我没有得到你的要求。顺便说一句,我加入了 2 个基于 circle_id 的集合
-
在您的查找中使用 foreignField: +'circle_id' 这会将您的字符串转换为数字。
-
我做了但没有弄错这是我在 circle_id $lookup 参数 'foreignField: nan.0' 之前添加 + 后得到的错误,必须是字符串,是双精度类型
-
为什么它们的类型不同?
标签: node.js string mongodb int aggregate