Object.bsonsize is not a function

In trying to call Object.bsonsize(doc) within mongosh in Compass but I’m getting: TypeError: Object.bsonsize is not a function. I also tried Object.bsonSize. According to version(), the mongosh I’m using is 1.1.8.

I assume this means it’s not available, although the docs suggest it is? Where am I going wrong here?

Note the warning at the top of the documentation page you linked:

The following document pertains to the mongo shell, included in the MongoDB Server Download. For information on the new MongoDB Shell ( mongosh ) refer to the mongosh documentation.

In this specific case, you can just use bsonsize(doc) and don’t need the Object. prefix.


Thanks for the quick response Anna! Yes, reading the incorrect documentation is definitely one area I was going wrong! :laughing: I don’t see any mention of bsonsize in that documentation, out of interest am I missing it or is that an omission? Is there a way from the docs that I should have been able to work that out?

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.