首页 > 数据库 > NoSQL > mongo 创建用户 建hash 分区 建索引
1. 设置Database
sh.enableSharding("database_name");
2. 创建Collection
use database_name
db.createCollection("collection_name");
sh.shardCollection("inv.collection_name",{orderCode:"hashed"});
3. 创建用户(mongos/mongod下都创建)
用户名:username
密码:password
权限:readWrite
db.createUser({user:"user_name",pwd:"password",roles:[{role:"readWrite",db:"database_name"}]})
4. 创建唯一索引
db.inv_record.createIndex({"orderCode": 1,"action": 1},{unique:true});
db.inv_record.createIndex({"createTime": 1,"status": 1 });
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28211342/viewspace-2213190/ ,如需转载,请注明出处,否则将追究法律责任。