1

I want to know what is the best way, to update previous records in the collection For example, i have

record 1){"name":"Bob"}
record 2){"name":"Alice"}

and now I realize that for new records i need also field age

record 3) {"name":"Bob",age:37}

Question: How is better to update record 1 and record 2

Writing migration for NoSQL seems to me not the best approach

  • 1
    You should use update with $set and option-multi:true and you must add to schema -age. – ŞükSefHam May 08 '18 at 17:34
  • Not clear which operation you mean here. If you need update "all" documents with a set value, then there's an `updateMany()` to do that. If you need to "marry up" individual data for each user to write their age from another source, then you are looping the collection results. If you have "multiple collections with joins" that you want to write in a single collection, then the same "loop and update" or possible "aggregate to new collection" applies. All listed in answers to existing questions. – Neil Lunn May 09 '18 at 01:33

0 Answers0