当前位置: 移动技术网 > IT编程>数据库>MongoDB > Mongo复制集同步验证的实例详解

Mongo复制集同步验证的实例详解

2017年12月01日  | 移动技术网IT编程  | 我要评论

mongo复制集同步验证的实例详解

第一步:在主节点上插入一条数据

sql代码 

rs0:primary> use imooc 
switched to db imooc 
rs0:primary> db.imooc.insert({"name":"imooc"}) 
writeresult({ "ninserted" : 1 }) 
 

第二步:在从节点查看数据,看是否同步

sql代码 

rs0:secondary> use imooc 
switched to db imooc 
rs0:secondary> show tables 
2017-06-14t19:33:06.118+0800 e query  [thread1] error: listcollections failed: { "ok" : 0, "errmsg" : "not master and slaveok=false", "code" : 13435 } : 
_geterrorwithcode@src/mongo/shell/utils.js:25:13 
db.prototype._getcollectioninfoscommand@src/mongo/shell/db.js:773:1 
db.prototype.getcollectioninfos@src/mongo/shell/db.js:785:19 
db.prototype.getcollectionnames@src/mongo/shell/db.js:796:16 
shellhelper.show@src/mongo/shell/utils.js:754:9 
shellhelper@src/mongo/shell/utils.js:651:15 
@(shellhelp2):1:1 
rs0:secondary> rs.slaveok() 
rs0:secondary> show tables 
imooc 
rs0:secondary> db.imooc.find() 
{ "_id" : objectid("59411e1c925a4f4db145e9af"), "name" : "imooc" } 
rs0:secondary> 

如有疑问请留言或者到本站社区交流讨论,大家共同进步,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网