Find largest document size in MongoDB

前端 未结 7 565
耶瑟儿~
耶瑟儿~ 2020-12-01 01:33

Is it possible to find the largest document size in MongoDB?

db.collection.stats() shows average size, which is not really representative because in my

7条回答
  •  天涯浪人
    2020-12-01 01:57

    You can use a small shell script to get this value.

    Note: this will perform a full table scan, which will be slow on large collections.

    let max = 0, id = null;
    db.test.find().forEach(doc => {
        const size = Object.bsonsize(doc); 
        if(size > max) {
            max = size;
            id = doc._id;
        } 
    });
    print(id, max);
    

提交回复
热议问题