mongodb - Unable to Understand the Document Size in Mongo Db -


this question has answer here:

i encountered strange behavior of mongo , clarify bit. wanted practically find out how many bytes single document consume when has 1 boolean attribute present in.

using stackoverflow, found out can use following command

object.bsonsize - javascript method should return size in bytes

while executing these commands got results confusing.

here provide steps incorporated

  1. i created database called mydatabase , stored collection called datarandom has 1 attribute called status , have set false.it assigned object id=558bf45d5ea9019aec35d7a2. ran following query in robomongo

    object.bsonsize(db.datarandom.find( {"_id"  :objectid("558bf45d5ea9019aec35d7a2")}));  

    i got 100 bytes.

  2. i ran second query on robomongo follows

    object.bsonsize(db.datarandom.findone( {"_id" :objectid("558bf45d5ea9019aec35d7a2")}));  

    i got output 31 bytes only!!!!!!

can explain why getting 2 different outputs when use find , findone when there 1 document in collection boolean attribute.

there multiples ways find out collection size or document size.

in scenario inserted 1 document 1 field status, 2 fields in 1 document _id , status

use following command

 use mydatabase  //to use particular database   db.datarandom.stats() //returns information of datarandom collection 

size gives documents size

count gives no of documents, etc.

more details collection stats link

edit

note:

find - returns cursor object

note: cursor- pointer result set of query.

findone - returns particular document, gives perfect size of document without padding space while using db.bsonsize.

collection.stats() - returns details collection, size field gives document size including padding space.

note: every document in mongodb stored in record contains document , space, or padding. padding allows document grow result of updates while minimizing likelihood of reallocations.

check storage characteristics

big note

even though have 1 document or many, find , findone behavior won't change.

first understand use what.

one question you

for example:

   [{status: true}] , {status :true}  

is same? whether gives same size?


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -