2

In my collection, my documents seem to be relatively similar. I need to know how much storage I'll need in my production server to store my documents, that's why I queried :

db.collectionName.stats()

My field avgObjSize was around 6442 bytes. I chose a random document in my collection, I typed :

Object.bsonsize(db.collectionName.find({"_id" :         ObjectId("5508497c51a990da07b07106")}))

And I obtained 810 bytes.

Why do I have this huge difference ?

I also noticed that more I store documents, more avgObjSize decreases... Is that normal ? (I checked, my documents are not empty.)

It's a development server, so I'm on Red Hat Enterprise Linux 5.8 and it's a 32bit version.

8

My field avgObjSize was around 6442 bytes. I chose a random document in my collection, I typed :

Object.bsonsize(db.collectionName.find({"_id" : ObjectId("5508497c51a990da07b07106")}))

And I obtained 810 bytes.

Why do I have this huge difference ?

The db.collection.find() method returns a cursor, so what you have calculated is the size of the cursor object rather than the size of a document.

You should use db.collection.findOne() to return a single document if you want to measure the BSON size:

Object.bsonsize(db.collectionName.findOne(
    {"_id" : ObjectId("5508497c51a990da07b07106") }
))

I also noticed that more I store documents, more avgObjSize decreases... Is that normal ? (I checked, my documents are not empty.)

The average is based on the size of the documents in the collection, so it sounds like your trend over time is to insert smaller documents. The normal behaviour depends entirely on your use case ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.