Note to self
Import/export with Mongodb
I needed to do a bulk import of some json data into a Mongodb database today and stumbled across Mongoimport for the first time which does the job nicely (it can do csv too, of course). Sometimes I need somewhere to make notes of the steps involved in doing things that aren't that common or don't happen too regularly otherwise I forget, so for my own future self and anyone else here's what I needed to do.
- Prepare the file. Mine was simple but more complex types can be imported:
{"name": "Dave", "address": "dave81@gmail.com"}
{"name": "John", "address": "johnx12@outlook.com"}
- Save it, and then run the mongoimport tool, specifying the database and collection followed by the datatype which in this instance is json (but can be csv too) like so:
mongoimport --db "traffic" --collection "teams" --ignoreBlanks --type json --file "teams.json"
and just in case you need to export it again:
mongoexport --db "traffic" --collection "teams" --out "teams.json"
- Done.
polyglot programmer - passionate, opinionated, cynic, realist