Hello I have a javascript file, that stores data in the mongodb. I would like to do two things
1) ask for the diskspace due to "db.mycol.stats();" or something like that and store the used storage size (should be "size" or storage size") into a var.
2) I want to store that var in a file - like e.g. .txt
I saw and used the following: (disksapce is an array with different disksizes, I would like to measure, (amount is a var))
var fso2 = new ActiveXObject("Scripting.FileSystemObject");
var b = fso2.CreateTextFile(file_diskspace, true);
for (m=0;m<diskspace.length;m++)
{
b.WriteLine(amount+ ":" + diskspace[m]+"\n");
}
b.Close();
somehow this does not work. (I'm using a linux server)
There are various reasons why this won't work. You can't typically write files from within a JS context (certainly not from within MongoDB's), ActiveXObject only exists on windows.
If you want to do this write the script by invoking print(db.getSiblingDB("yourDb").stats().storageSize);
and writing to a file (or piping the output to a file)
EDIT : Like so : mongo --quiet --eval "db.getSiblingDB('test').stats().storageSize" > size.text