如何在我的流星应用程序数据库中使用mongoimport? [英] how to use mongoimport with my meteor application database?
问题描述
我可以使用mongoimport
将csv数据导入非流星mongodb数据库,但是我不知道如何将csv导入我的流星app数据库.
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.
我学习了如何为流星应用程序(meteor mongo
)运行mongo shell,但无法从该shell运行mongoimport
.
I learned how to run the mongo shell for my meteor app (meteor mongo
) but I can't run mongoimport
from the shell.
mongoimport
的mongodb文档说
The mongodb docs for mongoimport
says
在此示例中,mongoimport将/opt/backups/contacts.csv中的csv格式的数据导入到在编号为27017的localhost端口上运行的MongoDB实例的users数据库中的集合联系人中.
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用户-集合联系人-类型csv --file/opt/backups/contacts.csv
mongoimport --db users --collection contacts --type csv --file /opt/backups/contacts.csv
但是当我运行mongod
时,启动流星应用程序并运行mongoimport
,它将导入到我的test
数据库中,而不是我的应用程序数据库中.
But when I run mongod
, start my meteor app, and run mongoimport
it imports to my test
database, not my app database.
我阅读了这个stackoverflow的评论:
I read this stackoverflow post comment:
使用mongoexport分别转储您的集合,然后使用mongoimport将文件导入流星mongodb实例中名为meteor的数据库中.流星mongo实例在端口3002上以bind_address 127.0.0.1运行,数据文件位于流星项目子目录.meteor/local/db
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
但是我不知道如何连接到该实例或如何使用mongoimport
命令将其定位.
But I don't understand how to connect to that instance or how to target it with the mongoimport
command.
推荐答案
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.
也不要忘记将端口放入(如果在 3000 上运行流星实例,通常是 3001 ),并且数据库通常是流星&不是用户,当您运行它
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
这篇关于如何在我的流星应用程序数据库中使用mongoimport?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!