Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-539

Script for finding size of a chunk given a document

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 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)
      }
      
      

            Assignee:
            scotthernandez Scott Hernandez (Inactive)
            Reporter:
            andre.defrere@mongodb.com Andre de Frere
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              7 years, 39 weeks, 1 day ago