字符串转换为数组在MongoDB中? [英] Convert string to array in Mongodb?
本文介绍了字符串转换为数组在MongoDB中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在蒙戈,我需要字段转换是这样的:
In Mongo, I need to convert fields like this:
音素:JH OY1 N个Z,
成这样的阵列
"phonemes" : [
"JH",
"OY1",
"N",
"Z"
]
我发现了一些code <一个href=\"http://blog.physalix.com/datas-manipulation-in-mongodb-rename-field-change-type-add-sub-document/\"相对=nofollow>这里这将字符串转换到一个数组,但它是我的目的,有点太简单,只有要创建一个单独的数组元素。
I found some code here which converts a string into an array, but it's a bit too simple for my purposes as there is only a single array element to be created.
db.members.find().snapshot().forEach( function (x) {
x.photos = [{"uri": "/images/" + x.photos}];
db.members.save(x);
});
时提供给我整个JavaScript语言从蒙戈外壳语句中?
Is the entire javascript language available to me from within mongo shell statements?
推荐答案
比我想象的要容易得多。只需使用JavaScript分裂功能。轰!
Much easier than I thought. Just use JavaScript split function. boom!
db.temp.find().snapshot().forEach( function (el) {
el.phonemes = el.phoneme.split(' ');
db.temp.save(el);
});
这篇关于字符串转换为数组在MongoDB中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文