Note the warning at the top of the documentation page you linked:
The following document pertains to the
mongoshell, 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.