我是mongo的新手,刚刚在笔记本电脑上创build了一个replica locale。
我试图从这里导入餐馆的演示数据库: https : //raw.githubusercontent.com/mongodb/docs-assets/primer-dataset/dataset.json
并执行了这个mongoimport命令:
mongoimport -v --db test --collection restaurants --drop --file dataset.json
结束导入只是停止在45%
2015-12-29T12:42:56.847-0500 filesize: 11880944 bytes 2015-12-29T12:42:56.847-0500 using fields: 2015-12-29T12:42:56.859-0500 connected to: localhost 2015-12-29T12:42:56.859-0500 ns: test.restaurants 2015-12-29T12:42:56.860-0500 connected to node type: replset 2015-12-29T12:42:56.860-0500 using write concern: w='majority', j=false, fsync=false, wtimeout=0 2015-12-29T12:42:56.861-0500 dropping: test.restaurants 2015-12-29T12:42:56.864-0500 using write concern: w='majority', j=false, fsync=false, wtimeout=0 2015-12-29T12:42:59.859-0500 [#########...............] test.restaurants 4.5 MB/11.3 MB (39.9%) 2015-12-29T12:43:02.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:05.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:08.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:11.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:14.849-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:17.849-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:20.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:23.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:26.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:29.849-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:32.849-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:35.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:38.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:41.849-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:44.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:47.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:50.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:53.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:56.850-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:43:59.849-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:44:02.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:44:05.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:44:08.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:44:11.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%) 2015-12-29T12:44:14.848-0500 [##########..............] test.restaurants 5.2 MB/11.3 MB (45.5%)
在奴隶有一个数据库testing创build,但如果我尝试做一个查找:db.restaurants.find();
我回头:
Error: error: { "$err" : "not master and slaveOk=false", "code" : 13435 }
这是我的主副本configuration:
repl1:PRIMARY> rs.config() { "_id" : "repl1", "version" : 7, "members" : [ { "_id" : 0, "host" : "mongo1:27017", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : { }, "slaveDelay" : 0, "votes" : 1 }, { "_id" : 1, "host" : "mongo2:27017", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : { }, "slaveDelay" : 0, "votes" : 1 }, { "_id" : 2, "host" : "mongo3:27017", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : { }, "slaveDelay" : 0, "votes" : 1 } ], "settings" : { "chainingAllowed" : true, "heartbeatTimeoutSecs" : 10, "getLastErrorModes" : { }, "getLastErrorDefaults" : { "w" : 1, "wtimeout" : 0 } } }
看起来奴隶们不认识到他们是复制品集合的一部分。
我在哪里可以find更多信息发生了什么?
结束导入只是停止在45%
这可能是好的,只是build立索引。 或者你可能会耗尽一些系统资源,或者它可能会很慢。 尾部mongod进程的日志以获取更多信息。 检查你的磁盘是否有空闲空间,并检查top或任何系统监视工具,你必须看到什么资源正在使用,而导入似乎停止在45%。
在奴隶有一个数据库testing创build,但如果我尝试做一个查找:db.restaurants.find();
我回头:
Error: error: { "$err" : "not master and slaveOk=false", "code" : 13435 }
如果没有先告诉你的驱动程序或者mongo shell,那么你不能在辅助数据上查询数据。 首先运行rs.slaveOk() ,然后运行find()查询。
这是一个防火墙阻止奴隶沟通回到主人。 主人能够与奴隶沟通,但奴隶无法回答。
如果你有一些类似的问题,如果你正在使用Centos7,请检查你的Firewalld
要导入你可以试试这个代码:
mongoimport --db <database-name> --collection <collection-name> --file ~/path/file-name.json