mongodb删除片键
1、查询库上所有的片键
mongos> use config
switched to db config
mongos> show collections
actionlog
changelog
chunks
collections
databases
lockpings
locks
mongos
settings
shards
system.indexes
tags
version
mongos> db.getCollection('collections').find({})
{ "_id" : "test.c1", "lastmod" : ISODate("2019-06-13T09:28:15.535Z"), "dropped" : false, "key" : { "_id" : 1 }, "unique" : false, "lastmodEpoch" : ObjectId("5d02172f4c21670698055037") }
2、删除某个片键
删除某个片键需要执行如下所有操作
mongos> db.collections.remove({_id:"test.c1"})
WriteResult({ "nRemoved" : 1 })
mongos> db.chunks.remove({ns:"test.c1"})
WriteResult({ "nRemoved" : 38 })
mongos> db.locks.remove({_id:"test.c1"})
WriteResult({ "nRemoved" : 1 })
mongos> use admin
switched to db admin
mongos> db.adminCommand("flushRouterConfig") ##刷新路由配置
{ "flushed" : true, "ok" : 1 }
好了,这就是mongodb删除片键的方法了,如有问题可与博主一起交流讨论!