一、读写分离
1、先向主库中插入一条测试数据
- [root@localhostbin]#./mongo--port28010
- MongoDBshellversion:1.8.1
- connectingto:127.0.0.1:28010/test
- rs1:PRIMARY>db.c1.insert({age:30})
- db.c2rs1:PRIMARY>db.c1.find()
- {"_id":ObjectId("4fc77f421137ea4fdb653b4a"),"age":30}
- [root@localhostbin]#./mongo--port28011
- connectingto:127.0.0.1:28011/test
- rs1:SECONDARY>showcollections
- ThuMay3122:27:17uncaughtexception:error:{"$err":"notmasterandslaveok=false",
- "code":13435}
- rs1:SECONDARY>