We have a collection in our database that is all schema-less and what not. The size of these documents is becoming problematic. The first step to fixing a problem is admitting you have one, right? To this end, I am trying to craft a query to report on the size of each document in our problem-child collection. In the mongo shell, the following works like a champ:
db.profiles.find().forEach( function( doc ) { print( "\"" + doc._id + "\", \"" + doc.projectName + "\", " + Object.bsonsize( doc) ); } );
...it produces output like...
"XQ531", "Mango#3.5,Mango#WL,Mango,MANGO#WL", 1912
"MJ8310", "Cheetah#UL", 913655
"MJ8311", "Cheetah#UL", 503
"MJ8312", "Cheetah#UL", 213510
"MJ8313", "Cheetah#UL", 317795
How do I get this output to pop out of some script and go directly into a CSV file? I plan to put this thing on some cron or something and run it daily. Could I make mongoexport do this?
As always, any advice is greatly appreciated.
Bob