mongodb exception: $concat only supports strings, not NumberInt32解决办法

mongodb exception: $concat only supports strings, not NumberInt32解决办法,第1张

mongodb exception: $concat only supports strings, not NumberInt32解决办法

今天在用mongodb *** 作aggregation的时候出现这个问题,我是想格式化日期,例如”2013-10-17 04:41:37 UTC”变成”10月17日”,
复制代码 代码如下:
'fdate' => { '$concat' => ['$date.month', '月', '$date.day', '日'] }
出现 exception: $concat only supports strings, not NumberInt32

原来$concat只能 *** 作字符串,不支持数字类型,解决办法是用$substr
复制代码 代码如下:
$date形如'2013-10-13 11:17:18 UTC'

'fdate' => { '$concat' => [ {$substr=>['$date', 5, 2]}, '月', {$substr=>['$date', 8, 2]}, '日'] }
$substr接受两个参数,一个是字符串的起点,一个是截取的字符串的长度。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/886245.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-14
下一篇 2022-05-14

发表评论

登录后才能评论

评论列表(0条)

保存