Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use config
- db.settings.find({_id : "chunksize"}]
- db.getSisterDB("config").chunks.find({ns : "mydb.mycollection"}).forEach(function(chunk) {
- db.getSisterDB("mydb").mycollection.find({},{_id : 0, partnerId , 1, id : 1}).min(chunk.min).max(chunk.max).count()
- })
- var ns = "mydb.mycollection" //the full namespace of the collection
- var key = {partnerId : 1, id : 1} //the shard key of the collection
- db.getSiblingDB("config").chunks.find({ns : ns}).forEach(function(chunk) {
- var ds = db.getSiblingDB(ns.split(".")[0]).runCommand({datasize:chunk.ns,keyPattern:key,min:chunk.min,max:chunk.max});
- print("Chunk: "+chunk._id +" has a size of "+ds.size+", and includes "+ds.numObjects+" objects (took "+ds.millis+"ms)")
- }
- )
- var collection = "products";
- var database = "products";
- var ns =database+"."+collection;
- rs.slaveOk(true)
- db.getSiblingDB("config").chunks.find({ns : ns}).forEach(function(chunk) {
- pMin = chunk.min.partnerId
- pMax = chunk.max.partnerId
- midR = {partnerId : {$gt : pMin , $lt : pMax}}
- lowR = {partnerId : pMin, id : {$gte : chunk.min.id}}
- if (pMin == pMax) lowR.id = {$gte : chunk.min.id, $lt : chunk.max.id}
- upR = {partnerId : pMax, id : {$lt : chunk.max.id}}
- a = db.getSiblingDB(database).runCommand({count : collection, query : lowR, fields : {partnerId :1, _id : 0}}).n
- b = db.getSiblingDB(database).runCommand({count : collection, query : midR, fields : {partnerId :1, _id : 0}}).n
- c=0
- if (pMin != pMax)
- c = db.getSiblingDB(database).runCommand({count : collection, query : upR, fields : {partnerId :1, _id : 0}}).n
- print(chunk.shard + "|"+tojson(chunk.min) +"|" +tojson(chunk.max)+"|"+a +"|"+b+"|"+ c +"|"+(a+b+c))
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement