Home  >  Q&A  >  body text

分布式 - 通过JAVA代码是否能够判断MongoDB集群的某个表设置了分片?

通过JAVA代码是否能够判断MongoDB集群的某个表设置了分片?

巴扎黑巴扎黑2743 days ago610

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-04-18 10:54:04

    You can retrieve the config collections. The collections in each document in the collections are sharded; you can also learn the specific situation of the sharding of the collection. 说着有点拗口

    The following example is one of the collections given in the official documentation:

    {
       "_id" : "records.pets",                             --Database name.Collection name
       "lastmod" : ISODate("1970-01-16T15:00:58.107Z"),
       "dropped" : false,
       "key" : {
             "a" : 1                                       --Shard key
       },
       "unique" : false,
       "lastmodEpoch" : ObjectId("5078407bd58b175c5c225fdc")
    }
    

    Use Java code to retrieve the above collection to get the required sharding information.

    For reference.

    Love MongoDB! Have Fun!

    reply
    0
  • Cancelreply