您的位置:首页 > 数据库 > Mongodb

MongoDB对集合分片

2020-07-16 05:19 507 查看

1 创建数据库,直接use database_name 切换至你想创建的数据库。

mongos> use DataPlatform
switched to db DataPlatform

2 创建集合 

mongos> db.createCollection("risk_dag_hive_to_mongo", {"autoIndexId":true})
{
"note" : "the autoIndexId option is deprecated and will be removed in a future release",
"ok" : 1
}

3 首先要对库DataPlatform开启分片功能

mongos> sh.enableSharding("DataPlatform");
{ "ok" : 1 }

可以通过 命令验证

sh.status()

4 对集合开启分片 

mongos>  sh.shardCollection("DataPlatform.risk_dag_hive_to_mongo",{"user_id":1})
{ "collectionsharded" : "DataPlatform.risk_dag_hive_to_mongo", "ok" : 1 }

通过命令验证  看截图中sharded已经为true,说明开启了分片

mongos> db.risk_dag_hive_to_mongo.stats()

5 为数据库创建账号 

mongos>  db.createUser(
...      {
...        user:"DataPlatform_rw",
...        pwd:"",
...        roles:[{role:"readWrite",db:"DataPlatform"}]
...      })
Successfully added user: {
"user" : "DataPlatform_rw",
"roles" : [
{
"role" : "readWrite",
"db" : "DataPlatform"
}
]
}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: