0

I have a situation where I have to get data from a stream and create a document in mongodb each time I get data from a stream. I can get the number of documents beforehand. I want to know how to determine the size of the documents on disk if and when the stream completes. But I would like to know this before I start my process. Is there a way to do this in mongodb.

I found Object.bsonsize(); but it can only find the size after a query complete.

As of right now I am taking the product of the number of objects(data) from the stream and size of each object which I assume to be uniform throughout the stream.

UVic
  • 1,671
  • 3
  • 14
  • 21
  • Before insert query in mongodb you can query to get total count. `db.collection.find().count()` – Ashwanth Madhav Apr 02 '19 at 12:44
  • I want the size of the object I am inserting ...if and when it is inserted not the count of documents already in the db.. – UVic Apr 02 '19 at 13:43
  • size of the object can calculate using `var size = Object.keys(myObj).length;` – Ashwanth Madhav Apr 02 '19 at 13:56
  • @AshwanthMadhav I don't think u understand the question... – UVic Apr 02 '19 at 14:26
  • MongoDB has no "query" method to determine a BSON size. There is **only** the utility method mentioned, and you either must run that on a returned object or within a `mapReduce()`. – Neil Lunn Apr 03 '19 at 07:09

0 Answers0