[DOCS-539] Script for finding size of a chunk given a document Created: 21/Sep/12  Updated: 27/Jul/16  Resolved: 27/Jul/16

Status: Closed
Project: Documentation
Component/s: cookbook
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Andre de Frere Assignee: Scott Hernandez (Inactive)
Resolution: Won't Fix Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Participants:
Days since reply: 7 years, 29 weeks ago

 Description   

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)
}
 



 Comments   
Comment by Emily Hall [ 27/Jul/16 ]

Closed for housekeeping on 7/27/2016 by Emily Hall.
If you require additional support, please open a new ticket for prioritization.
Thanks,
Emily

Generated at Thu Feb 08 07:38:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.