If it is a one time thing to do, its no big deal. Run a query like "db.foo.find();" in your mongo shel and paste the entire output to a editor like Textpad or Sublime text, do a column block ( In sublime text it is Ctrl + scroll wheel click & Drag ) , , paste it which will extend to another field, rename the newly pasted column as you want it, once done, do a regex to just edit the whole bunch as "^" with "db.foo.insert({" and at the "$" as "});"
It is like the following steps.
- You pasted the output like
{ 'field1' : value, 'field2' : value2 , 'field3' : value4 };
- copy the last set and extend using the editor column block
{ 'field1' : value, 'field2' : value2 , 'field3' : value4 };
- Now insert the appropriate words to make it look like a command for mongo
db.foo.insert({ 'field1' : value, 'field2' : value2 , 'field3' : value4 });
- Now copy them all and paste it in your mongo shell which will just do the whole thing for you as you want it. Test it once and redo the whole thing just after you cleanup the collection otherwise it will insert duplicates. Also remove the "_id" fields in the output since it will conflict when you attempt to insert again !!
Now, every single line in your editor shows a valid mongo command that can be pasted to your shell to insert a new document to your collection. so test it once and it works fine, clean up your entire collection like "db.foo.remove({});" and paste the entire command from the editor which will do it in a giffy.
It may be difficult when you attempt for the first time, but if you get it right its gonna be a handy thing for you to work along whenever you want it.... !!