0

I want to upsert the result of a find() query into another collection.

Currently I do it this way:

db.source_collection.find(
    { <my filters> },
    { <my columns> }
).forEach(function (doc) {
    db.target_collection.update(
        { <my key > },
        { <my fields to upsert> }
        { multie : true, upsert: true }
    )
}) 

Is there faster way to do this?

Mouette
  • 289
  • 1
  • 6
  • 17
  • http://stackoverflow.com/questions/9711529/save-subset-of-mongodb-collection-to-another-collection – dikesh Feb 03 '16 at 13:07
  • The $out is much faster but it will create or replace the collection. I look for a way to do an upsert – Mouette Feb 03 '16 at 13:22

0 Answers0