Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the fhe size of the specific Document in MonogoDB Collection?

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.

like image 971
Rakesh Avatar asked Feb 24 '18 08:02

Rakesh


People also ask

What is document size in MongoDB?

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.

How big is a 16MB MongoDB document?

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.

Which of the following command can be used to check the size of a collection named posts?

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?

How to get the size of all the documents in MongoDB?

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 −

What is the use of bsonsize in MongoDB?

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 the size of a filtered dataset in MongoDB?

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.

What happened to cursor and collection count() in MongoDB?

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.


1 Answers

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'}))
like image 114
mickl Avatar answered Sep 30 '22 05:09

mickl