1、创建集合
> db.createCollection("mySet", {capped:true,size:6142800, max :10000 })
{ "ok" : 1 }
2、插入数据
> db.mySet.insert({item : "item", qty : 15})
WriteResult({ "nInserted" : 1 })
3、查询数据
> db.mySet.find()
{ "_id" : ObjectId("62ab45749c835e6af2150745"), "item" : "item", "qty" : 15 }
4、批量插入数据
for (var i = 1; i <= 10; i++){db.mySet.insert( { x : i , name: "Liqing" , class:"1120", sex:"woman"})}
rs.initiate( {
... _id : "rs1",
... members: [
... { _id: 0, host: "10.1.1.252:27017" },
... { _id: 1, host: "10.1.1.253:27017" },
... { _id: 2, host: "10.1.1.254:27017" }
... ]
... })
1、查看集群中各节点的状态:
rs0:PRIMARY> rs.status()
2、查看集群中各节点配置情况:
rs0:PRIMARY> rs.conf()
3、主节点降级为从节点:
rs0:PRIMARY> rs.stepDown()
4、将从节点添加至集群中:
rs0:PRIMARY> rs.add("172.16.1.31:27017")
5、从集群中移除从节点:
rs0:PRIMARY> rs.remove("172.16.1.31:27017")