Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
Calculate BSONObj size before storing to mongo JavaScript

I'm trying to figure out, how to calculate size before storing some data to MongoDB. Since I wrote a script that parses data, combining them in a single document and trying to do instance.save().

So far I am getting an error such as:

BSONObj size: 17102819 (0x104F7E3) is invalid. Size must be between 0 and 16793600(16MB)

I don't want to use gridFS, because it is architecture-dependent and the project is big enough to use it, so far I decided to skip such documents that have a greater size than required.

I found the article about: How to calculate existing document BSONSize

Link to the article: https://betterprogramming.pub/how-to-calculate-mongodb-document-size-in-node-js-f463b8457f27

But, I need to figure out, how to calculate it before storing it in the database

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try this:

Object.bsonsize({field: "value"})
-> 22

Look like this method is available only in legacy shell mongo but not in new mongosh. For mongosh, see https://stackoverflow.com/a/34768008/3027266

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!