javascript - Nodejs mongodb fetching document size without actually fetching cursor -
my question is, how can cursor
size (in kbs) without fetching ?
i've examined lot of question such here don't want fetch query result learn how kb it.
i want like:
var mongoclient = require('mongodb').mongoclient, test = require('assert'); mongoclient.connect('mongodb://localhost:27017/test', function(err, db) { var collection = db.collection('simple_query'); // insert bunch of documents testing collection.insertmany([{a:1}, {a:2}, {a:3}], {w:1}, function(err, result) { test.equal(null, err); collection.find(/**some query*/).size(function(err, size) { test.equal(null, err); test.equal(32111351, size); // in bytes or kilobytes whatever db.close(); }); }); });
something this?
var avgsize = db.collectionname.stats().avgobjsize; // ... collection.count(/* query */, function(err, count) { var approximatesize = count*avgsize; // work simple database models }
i know not perfect, best way found.
Comments
Post a Comment