Object.bsonsize() returns invalid value (> 16MB)

Lan Ke shared this problem 4 years ago
Solved

On our database, when using

Object.bsonsize(...)

return result are more than 16MB (which is the limit of Mongo) for document closed to 16MB.

On native mongo shell, the result is correct.


The command used is

Object.bsonsize(db.somecollection.findOne({_id: ObjectId("5cf4ad28e4b01b4f149171ad")}))
on Mongo Shell (and many other utilities), the outcome is 16358953 but in NoSQLBooster (5.1.8), the outcome is 30159454.

Best Answer
photo

Resolved in 5.1.0

Replies (9)

photo
1

By the way, the function calculateObjectSize() has the same problem - probably underline code is the same.

photo
1

I created a document of about 16M (16774947), tried it a few times, and couldn't reproduce your issue. If you're reporting a bug, please make sure you include steps to reproduce it.

  • NoSQLBooster Version
  • MongoShell Version
  • Operating System (Windows/Mac/Ubuntu):
  • Expected Behavior
  • Actual Behavior
  • How to Reproduce (please include sample JSON data)
  • Screenshots

photo
1

As mentioned in the original report, version of NoSQLBooster is 5.18. Here are other information

  • OS - Mac.
  • MongoDB version: 4.0.2

photo
1

OK, the key here is the reproduction step of bug, without which it is difficult to solve the problem by guessing.

We use the following script to create a big document, It's close to 16m in size. I tried a few times, but can't recall this issue.

db.bsonSizeBug.remove({_id:1});
db.bsonSizeBug.insertOne({_id:1, str: '#'.repeat(15.5*1024*1024)});

Object.bsonsize(db.bsonSizeBug.findOne({_id:1})

photo
1

this can be reproduced:

1. download a more complicate JSON file, for example, like this one https://data.cdc.gov/api/views/bi63-dtpu/rows.json?accessType=DOWNLOAD

2. replicate the data to 71000 rows - this will make the bson size to be around 15mb

3. using mongoimport to import this JSON file


Here is the result from mongo shell

mongos> Object.bsonsize(db.testSize.findOne({_id:ObjectId("5cfefa9ed8ea4d9d536d29d7")}))

15692505


however, in NoSQLBooster, it returns "22704873" which clearly violate the limitation (16mb)

photo
1

Thank you for your bug report.

We have worked out a new test build to resolve this issue, please download and give it a try.

MacOS: https://nosqlbooster.com/s3/download/releasesv5/nosqlbooster4mongo-5.1.9-beta.1.dmg

photo
1

Thank you for the quick turn-around. I will test it out.

photo
1

5.1.9beta1 works fine - this problem is no longer present.

photo
1

Resolved in 5.1.0

Leave a Comment
 
Attach a file