如何在MongoDB中将字符串字段数组更新为对象数组?

时间:2020-05-14 00:49:35

标签: mongodb aggregation-framework

如何使用MongoShell命令将文档的array of string更新为array of object

people
[
   { 
      name: 'John',
      friends: ['Mary', 'Jane', 'Steve']
   },
   { 
      name: 'Michael',
      friends: ['John']
   },
...
]

people
[
   { 
        name: 'John',
        friends: [{ name: 'Mary' }, {name: 'Jane'}, {name: 'Steve'}]
   },
   { 
        name: 'Michael',
        friends: [{name: 'John'}]
   },
   ...
]

0 个答案:

没有答案