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.
Document Size Limit The maximum BSON document size is 16 megabytes. The maximum document size helps ensure that a single document cannot use excessive amount of RAM or, during transmission, excessive amount of bandwidth. To store documents larger than the maximum size, MongoDB provides the GridFS API.
With its 16Mb limit, a MongoDB document can easily store around 2 million values of 64-bit numbers (also dates and booleans). But strings are a special case. Each UTF-8 character takes one byte.
To view the statistics for a collection, including the data size, use the db. collection. stats() method from the mongo shell. Q 22 - Which of the following commands can cause the database to be locked?
Get the size of all the documents in a MongoDB query? To get the size of all the documents in a query, you need to loop through documents. Let us first create a collection with documents −
The $bsonSize aggregation pipeline operator was introduced in MongoDB 4.4 for the purpose of returning the size of a BSON document. You can use $bsonSize to return the total size of all documents in the collection by combining it with the $group and $sum operators.
How to get a filtered dataset size You can use Object.bsonsize<object> to get object size in bytes. // this will work in the mongo shell only const doc = db.coll.findOne (<queryFilter>); Object.bsonsize (doc); It is possible to get the object size in the Node.js environment using bson library.
MongoDB drivers compatible with the 4.0 features deprecate their respective cursor and collection count () APIs in favor of new APIs for countDocuments () and estimatedDocumentCount () . For the specific API names for a given driver, see the driver documentation.
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'}))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With