MongoDB rename database field within array

前端 未结 6 699
难免孤独
难免孤独 2020-11-28 09:16

I need to rename indentifier in this:

{ \"general\" : 
  { \"files\" : 
    { \"file\" : 
      [  
        {  \"version\" : 
          {  \"sof         


        
6条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 10:00

    I had a similar problem. In my situation I found the following was much easier:

    1. I exported the collection to json:
    mongoexport --db mydb --collection modules --out modules.json
    
    1. I did a find and replace on the json using my favoured text editing utility.

    2. I reimported the edited file, dropping the old collection along the way:

    mongoimport --db mydb --collection modules --drop --file modules.json
    

提交回复
热议问题