Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

mongodb - how to use mongoimport with my meteor application database?

I'm able to use mongoimport to import csv data into a non-meteor mongodb database, but I can't figure out how to import a csv into my meteor app database.

I learned how to run the mongo shell for my meteor app (meteor mongo) but I can't run mongoimport from the shell.

The mongodb docs for mongoimport says

In this example, mongoimport imports the csv formatted data in the /opt/backups/contacts.csv into the collection contacts in the users database on the MongoDB instance running on the localhost port numbered 27017.

mongoimport --db users --collection contacts --type csv --file /opt/backups/contacts.csv

But when I run mongod, start my meteor app, and run mongoimport it imports to my test database, not my app database.

I read this stackoverflow post comment:

Use mongoexport to dump your collections individually, then mongoimport to import the files into the db named meteor in the meteor mongodb instance. The meteor mongo instance runs on port 3002 with bind_address 127.0.0.1, and the data files are in the meteor project subdirectory .meteor/local/db

But I don't understand how to connect to that instance or how to target it with the mongoimport command.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Looks like I just answered your comment in Rahuls wonderful answer. Anyway download mongodb from mongodb.org for your OS (or a package manager like macports) and use the tool provided in the bin folder. mongoimport isn't a command in the mongo shell, it's an executable that runs separately.

Also don't forget to put the port in (usually 3001 if you're running your meteor instance at 3000), also the db is usually meteor & not users when you run it

mongoimport -h localhost:3001 --db meteor --collection contacts --type csv --file /opt/backups/contacts.csv

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...