【发布时间】:2020-08-26 00:33:54
【问题描述】:
当有mongod已经有数据时,配置shard时数据不可见 详细地 两个mongod有一个同名的集合,存储如下数据 信息(A,B mongod)
DB : db_test
Collection : test_log
魔神
{ "_id" : ObjectId("5f44cfa372c25aeff48e66d3"), "skey" : 100, "data" : 1 }
B mongod
{ "_id" : ObjectId("5f44cf731eadcef49cd93e7b"), "skey" : 200, "data" : 2 }
在 Mongos 中,我执行了以下命令
mongos> sh.addShard("A.MASTER:21011")
{ "shardAdded" : "shard0000", "ok" : 1 }
mongos> sh.addShard("B.SLAVE1:21011")
{ "shardAdded" : "shard0001", "ok" : 1 }
mongos> sh.addShardTag("shard0000", "master")
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
mongos> sh.addShardTag("shard0001", "slave_1")
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
mongos> sh.enableSharding("db_test")
{ "ok" : 1 }
mongos> sh.shardCollection("db_test.test_log", {skey:1})
{ "collectionsharded" : "db_test.test_log", "ok" : 1 }
mongos> sh.addTagRange("db_test.test_log", {skey:100}, {skey:199}, "master")
WriteResult({
"nMatched" : 0,
"nUpserted" : 1,
"nModified" : 0,
"_id" : {
"ns" : "db_test.test_log",
"min" : {
"skey" : 100
}
}
})
mongos> sh.addTagRange("db_test.test_log", {skey:200}, {skey:299}, "slave_1")
WriteResult({
"nMatched" : 0,
"nUpserted" : 1,
"nModified" : 0,
"_id" : {
"ns" : "db_test.test_log",
"min" : {
"skey" : 200
}
}
})
我在 mongos 中查找了数据(执行了“查找,聚合 ..”命令) 结果
mongos> db.test_log.find()
{ "_id" : ObjectId("5f44cfa372c25aeff48e66d3"), "skey" : 100, "data" : 1 }
在分片之前,我执行了 Command (create index (to use shardkey))
mongos> db.test_log.createIndex({ "skey": 1 });
{
"raw" : {
"A.MASTER:21011" : {
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
},
"ok" : 1
}
我想知道有什么问题 在mongos中创建索引的时候,我也很好奇只分配给A.master的部分。 请..
【问题讨论】: