flimflam57
flimflam57

Reputation: 1334

Easiest way to replace existing mongo collection with new one in Meteor

I have a csv file that I've imported into a Meteor project and I've updated the csv file (added a couple of columns with data) and I'd like to re-import the csv file. If I just import it again, will it over-write the first one? Or would I have two collections with the same name? What's the best way to do this?

Upvotes: 1

Views: 771

Answers (1)

somallg
somallg

Reputation: 2043

If you re-import the file again, it will do insert not update to the collection So if your collection have a unique key index on a field (like _id because by default _id is indexed and unique) and that field is a column in the csv file. When you import again, mongodb will throw an error saying you have violated a unique unique constraint and stop, your old data is untouched.

If not, your collection don't have any other unique key index and _id is not a column in the csv file. Then if you re-import, your collection will have duplicate records with the old data and the new data that you just imported.

Either way, the result is not what you wanted.

You can't have 2 collections with the same name in the same database.

Easiest way to do: if your data is not important, you could just drop the collection and import again

Else you will have to update the document in mongodb (using mongo console or write a script)

Upvotes: 4

Related Questions