MongoDB对集合分片

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"
		}
	]
}

 

posted @ 2020-04-21 13:54  DBA社区  阅读(244)  评论(0编辑  收藏  举报