Split string into an array of substrings or characters in MongoDB

后端 未结 4 1706
我在风中等你
我在风中等你 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:19

    How to split a string into an array?

    In any halfway modern JavaScript engine, it is

    var myString = 'foo bar baz';
    var myArray = myString.split(' ');
    

    which should work even on the shell.

    Does MongoDB's shell provide the full feature set of JavaScript?

    Internally, since MongoDB 2.4 Google's V8 engine is used, which conforms ECMA-262. Expect all functionality defined in this standard at least.

    I haven't checked it, but some objects you know from the browser really don't make much sense in the mongo shell. All DOM related, that is. So before using them, I'd rather check wether they exist right away.

提交回复
热议问题