MongoDB exception: $concat only supports strings, not NUMBERINT32 solution _mongodb

Source: Internet
Author: User
Tags mongodb

Today, when I use MongoDB to manipulate aggregation, I want to format dates like "2013-10-17 04:41:37 UTC" into "October 17",

Copy Code code as follows:

' FDate ' => {' $concat ' => [' $date. Month ', ' month ', ' $date. Day ', ' th ']}

Appear exception: $concat only supports strings, not NumberInt32

Originally $concat can only manipulate strings, do not support numeric types, the solution is to use $SUBSTR

Copy Code code as follows:

$date-shaped like ' 2013-10-13 11:17:18 UTC '

' FDate ' => {' $concat ' => [{$substr =>[' $date ', 5, 2]}, ' month ', {$substr =>[' $date ', 8, 2]}, ' Day ']}


$SUBSTR accepts two parameters, one is the starting point of the string, and the other is the length of the intercepted string.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.