How to update ~20,000 records in MongoDB with this criteria

前端 未结 1 1475
渐次进展
渐次进展 2020-12-07 05:36

I have a MongoDB document that looks like the following:

\"sport\": \"NFL\",
\"team_id\": 5,
\"week_num\": 6,
\"meta\": {
   .... more data ....,
   \"season         


        
相关标签:
1条回答
  • 2020-12-07 06:16

    The problem is that during the update, you can not refer the document you are updating. So you can not achieve what you want in one query.

    You need to iterate through all the documents and save them one by one:

    db.yourCollection.find({}).forEach(function(doc) {
      doc.season_year = doc.meta.season_year;
      db.yourCollection.save(doc);
    });
    
    0 讨论(0)
提交回复
热议问题