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接受两个参数,一个是字符串的起点,一个是截取的字符串的长度。

本文mongodb exception: $concat only supports strings, not NumberInt32如何解决办法到此结束。我们的生命,就是以不断出发的姿势得到重生。小编再次感谢大家对我们的支持!

标签: 解决办法 concat