5

I have 100k documents in an MonoDB Collection, the document({id : '789736363828292'}) has 20k Documents/Records. I would like find the memory utilized by that particular document.

Please help me to find the memory size in MB in MongoDB console.

B--rian
  • 5,578
  • 10
  • 38
  • 89
Rakesh
  • 65
  • 1
  • 2
  • 11
  • 1
    Possible duplicate of [Mongo = get size of single document](https://stackoverflow.com/questions/22008822/mongo-get-size-of-single-document) – ThinkBonobo Aug 13 '19 at 20:00

1 Answers1

9

You can use Object.bsonsize in MongoShell which will return a BSON size (in bytes) of one document. Try

Object.bsonsize(db.col.findOne({id : '789736363828292'}))
mickl
  • 48,568
  • 9
  • 60
  • 89
  • 2
    @Rocky why do you want to add a date range ? `Object.bsonsize` takes one and exactly one document. – mickl Feb 24 '18 at 13:29
  • 3
    For anyone else who missed it, **you must use `findOne` instead of `find`** to get the correct size – Sam Jun 26 '19 at 05:04