SHARE
TWEET

Untitled

a guest Feb 21st, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use config
  2. db.settings.find({_id : "chunksize"}]
  3.    
  4. db.getSisterDB("config").chunks.find({ns : "mydb.mycollection"}).forEach(function(chunk) {
  5.      db.getSisterDB("mydb").mycollection.find({},{_id : 0, partnerId , 1, id : 1}).min(chunk.min).max(chunk.max).count()
  6. })
  7.    
  8. var ns = "mydb.mycollection" //the full namespace of the collection
  9. var key = {partnerId : 1, id : 1} //the shard key of the collection
  10.  
  11. db.getSiblingDB("config").chunks.find({ns : ns}).forEach(function(chunk) {
  12.         var ds = db.getSiblingDB(ns.split(".")[0]).runCommand({datasize:chunk.ns,keyPattern:key,min:chunk.min,max:chunk.max});
  13.         print("Chunk: "+chunk._id +" has a size of "+ds.size+", and includes "+ds.numObjects+" objects (took "+ds.millis+"ms)")
  14.     }
  15. )
  16.    
  17. var collection = "products";
  18. var database = "products";
  19. var ns =database+"."+collection;
  20. rs.slaveOk(true)
  21. db.getSiblingDB("config").chunks.find({ns : ns}).forEach(function(chunk) {
  22.   pMin = chunk.min.partnerId
  23.   pMax = chunk.max.partnerId
  24.   midR = {partnerId : {$gt : pMin , $lt : pMax}}
  25.   lowR = {partnerId  : pMin,  id : {$gte : chunk.min.id}}
  26.   if (pMin == pMax) lowR.id = {$gte : chunk.min.id, $lt : chunk.max.id}
  27.   upR  = {partnerId  : pMax,  id : {$lt : chunk.max.id}}
  28.   a = db.getSiblingDB(database).runCommand({count : collection, query : lowR, fields :    {partnerId :1, _id : 0}}).n
  29.   b = db.getSiblingDB(database).runCommand({count : collection, query : midR, fields :    {partnerId :1, _id : 0}}).n
  30.   c=0
  31.   if (pMin != pMax)
  32.     c = db.getSiblingDB(database).runCommand({count : collection, query : upR, fields :    {partnerId :1, _id : 0}}).n
  33.   print(chunk.shard + "|"+tojson(chunk.min) +"|" +tojson(chunk.max)+"|"+a +"|"+b+"|"+ c     +"|"+(a+b+c))
  34.   })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top