-
Type: Improvement
-
Resolution: Won't Fix
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: cookbook
-
Labels:None
Created a script to find the size of a chunk given a document. Makes use of the datasize command, so may not be ideal for manual. Also may not be best performance, but is useful nonetheless.
ChunkInfo = function(ns,doc){ var configDB = db.getSiblingDB("config"); var db1 = db.getSiblingDB(ns.split(".")[0]); var key = configDB.collections.findOne({_id:ns}).key; var sk = db1.getCollection(ns.split(".")[1]).findOne(doc, key); //Find Shard Key from given doc. if(!sk){ print("Can't find chunk!"); return; } var chunk = configDB.chunks.find({"ns" : ns, max: {$gt:sk} }).sort({min:1}).limit(1).next(); var dataSizeResult = db1.runCommand({datasize:chunk.ns, keyPattern:key, min:chunk.min, max:chunk.max}); print("***********Chunk Information***********"); printjson(chunk); print("Chunk Size: "+dataSizeResult.size) print("Objects in chunk: "+dataSizeResult.numObjects) }