Bulk update/upsert in MongoDB?

StackUnderflow picture StackUnderflow · Dec 14, 2010 · Viewed 16.2k times · Source

Is it possible to do bulk update/upsert (not insert) in MongoDB?

If yes, please point me to any docs related to this?

Thanks

Answer

Justin Jenkins picture Justin Jenkins · Dec 14, 2010

You can use the command line program mongoimport it should be in your MongoDB bin dir ...

There are two options you'll want to look into to use upsert ...

--upsert insert or update objects that already exist
--upsertFields arg comma-separated fields for the query part of the upsert. You should make sure this is indexed

More info here: http://www.mongodb.org/display/DOCS/Import+Export+Tools

Or just do ...

$ mongoimport --help