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"
}
]
}
本文详细介绍了如何在MongoDB中创建数据库、集合、开启分片功能,并为数据库创建账号的过程。首先,通过use命令创建数据库并切换至该数据库。接着,使用createCollection方法创建集合,随后对数据库和集合启用分片功能。最后,通过createUser方法为数据库创建读写账号。
1736

被折叠的 条评论
为什么被折叠?



