2

I need to add a field to every document inside a collection and copy. The value of the new field should be a field that already exists in the document.

The following solution is way to slow because it's about 400k documents and it only updates 80 documents a seconds roughly.

db.application.find().forEach(
  function (elem) {
    db.application.updateOne(
      {_id: elem._id},
      {$set: {sourceRaw: elem.source}}
    )
  }
);

Because of version 4.0 I can't use aggregations inside updateMany or bulkWrite.

Whats the fastest way to copy a field in AWS DocumentDB (MongoDB 4.0.0)?

  • Any convenient field that you could use to filter down the material in `find` and start several updates in parallel? Note that writes are relatively expensive so even if you have a way to address the 400K docs as (say) 10 chunks of 40K, you might not get aggregated 800 updates/sec. – Buzz Moschetti Feb 25 '22 at 18:54
  • @BuzzMoschetti thanks for the hint, I found a way to set known documents via the `updateMany` field and set the rest that is unknow via the cursor. About 90% of the documents are with known values. Sadly that documentDB doesnt have the merge operator or updateMany via aggregation. – Daniel Stieglmayr Feb 28 '22 at 07:57

0 Answers0