[英]Obtaining DocumentReference of Firestore document without fetching document
[英]Nodejs mongodb fetching document size without actually fetching cursor
我的問題是,如何在不實際獲取cursor
情況下獲得其cursor
大小(以KB為單位) ?
我已經檢查了很多問題,例如這里,但是我不想獲取查詢結果以了解它有多少KB 。
我只想要這樣的東西:
var MongoClient = require('mongodb').MongoClient,
test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
var collection = db.collection('simple_query');
// Insert a bunch of documents for the 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();
});
});
});
像這樣嗎
var avgSize = db.collectionName.stats().avgObjSize;
// ...
collection.count(/* some query */, function(err, count) {
var approximateSize = count*avgSize; // This could work for simple database models
}
我知道它並不完美,但這是我發現的最好方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.