I encountered a strange behavior of mongo and I would like to clarify it a bit...
My request is simple as that: I would like to get a size of single document in collection.
I found two possible solutions:
In the previous call of Object.bsonsize()
, Mongodb returned the size of the cursor, rather than the document.
Correct way is to use this command:
Object.bsonsize(db.test.findOne())
With findOne()
, you can define your query for a specific document:
Object.bsonsize(db.test.findOne({type:"auto"}))
This will return the correct size (in bytes) of the particular document.