In: Computer Science
In MongoDB using Linux how do you
Execute the command to find the size of a single document of your choosing from the enron database
Execute the command to find the size of the collection of documents in the enron database
1. In MongoDB for finding the size of a single document from database you have to execute following commands-
>bsonSize operator to get thedocument size.
-db.test.aggregate([
{
"$project":{
"name": abc,
"object_size":{ "$bsonSize": "$$ROOT"}
}
}
])
also
>Object.bsonSize(db,test.findOne({type:"auto"})) this instruction will gives you document size in bytes.
also for more information you can use following commands,
>dbStats.avgObjSize- this command will give you average size of documents in bytes. this is datasize divided by the number of documents.
2.Command to find the size of collection of documents,
>dbStats.objects- this command will give you a count of the number of objects i.e. documents in the database across all collections means size of collection of documents.
>db.runCommand( {<count>}) -to run a command against the current database,use following command to count number of documents
for more information you can use following command,
>db.collection.stats() - this function or command can help you to get all the information we need about the sizeof our collection using the stats() funtion on collection.