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 });