Out to a spreadsheet, and back again

MongoLoader » Use cases » Export, edit, import back

Download MongoLoader Free Trial »     Buy MongoLoader Now »

The situation

Not every correction happens in an application. A price list gets updated by hand, a list of product descriptions is rewritten by the marketing team, a set of customer records is fixed in bulk after a data problem. The practical way to do that work is a spreadsheet - and then it has to go back.

Exporting is the easy half. Loading the edited file back is where it goes wrong: a plain import adds a second copy of every row, and now the collection has duplicates with different values.

What you do

  1. Export the collection to Excel or CSV, with the fields the editor needs. Saving it as a session means the next export is one click.
  2. Let the file be edited - the rows that did not change stay in place.
  3. Import the file back into the same collection, and choose update or upsert rather than insert.
  4. Map the incoming fields onto the document fields, and nominate the key the match is made on - the field that identifies a document (_id, or your own business key).

Mapping the fields of an incoming file onto a MongoDB collection in MongoLoader

With upsert, a row whose key already exists updates that document; a row with a new key becomes a new document. That is what makes the round trip repeatable - the same file can be loaded twice without the collection growing.

What it will not do

Related

The two halves on their own: export a collection to a file, import a file into a collection. Cleaning the export before it goes out: clean the data on the way out. Both directions in one tool: one tool for both directions. Repeating it: sessions, command line.