Split string into an array of substrings or characters in MongoDB

后端 未结 4 1713
我在风中等你
我在风中等你 2020-12-16 05:22

I need to convert fields like this:

{ 
    \"_id\" : ObjectId(\"576fd6e87d33ed2f37a6d526\"), 
    \"phoneme\" : \"JH OY1 N Z\" 
}

into an a

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-16 06:08

    This should work with Mongo 3.4+ (see here for more info). This is a bit more concise than user3100115's answer.

    db.members.aggregate(
        [
            { "$addFields": { 
                "phonemes": { "$split": [ "$phoneme", " " ] } 
            }},
            { "$out": "members" }
        ]
    )
    

提交回复
热议问题