mongo 创建用户 建hash 分区 建索引
更新:HHH   时间:2023-1-7


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


返回关系型数据库教程...