How to import data file in mongoDb

# Run MongoD process and file below

MQ428GG8WL:week2 asee2278$ mongoimport –db students –collection grades –file grades.json

MQ428GG8WL:week2 asee2278$  mongoimport --db users --collection contacts --type csv --headerline --file /opt/backups/contacts.csv

Note : Do not fire this command in mongo shell, fire it on bash with directory where your json or import file eg grades.json is there. CSV


Avoid using mongoimport and mongoexport for full instance production backups. They do not reliably preserve all rich BSON data types, because JSON can only represent a subset of the types supported by BSON. Use mongodump and mongorestore as described in MongoDB Backup Methods for this kind of functionality.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.