Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

136
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda