2016/01/20

mongodb 2.6 command 小記



設定 replica set 相關

初始化 replica set

var config = { _id : "repl", members : [ {_id : 0, host : 'repl1:27017'}] };
rs.initiate(config);

修改 replica set 設定

var config = rs.conf();
config.members[1].priority = 0;
rs.reconfig(config);

加入仲裁者

rs.addArb('replarb:27017');

權限相關

新增 user

db.createUser(
  {
    user: "username",
    pwd: "password",
    roles: [
      'userAdminAnyDatabase',
      'dbAdminAnyDatabase',
      'readWriteAnyDatabase'
    ]
  }
);

移除 user

db.removeUser('username');

現有 user 加入新權限角色

db.grantRolesToUser(
  "backupuser",
  [
    { role: "backup", db: "admin" },
    { role: "restore", db: "admin" }
  ]
);

Capped Collections
建立一個有大小/筆數限制的collection
官方文件: capped-collections

// set on create
db.createCollection( "<collection name>", { capped: true, size: <size in byte>[, max : <num of max documents>] } );

// set on exists
db.runCommand({"convertToCapped": "<collection name>", size: <size in byte>[, max : <num of max documents>]});

沒有留言:

張貼留言