How to use the calculateObjectSize function from bson

Find comprehensive JavaScript bson.calculateObjectSize code examples handpicked from public code repositorys.

1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
const getObjSize = (obj) => {
	if (!obj) {
		return 0;
	}


	return BSON.calculateObjectSize(obj) / (1024 * 1024);
};


const filterDocuments = (rows) => {
	const size = getObjSize(rows);
fork icon7
star icon0
watch icon3

365
366
367
368
369
370
371
372
373
374
    data = new BSON.Binary(BSON.serialize(json));
    relevantDocs.push({ storageId: storageId, data });
}

let docsSize = 0;
for (let doc of relevantDocs) docsSize += BSON.calculateObjectSize(doc);

if (docsSize > 1024 * 500) {
    throw context.error("Storage per guild cannot exceed 500kb!");
}
fork icon0
star icon0
watch icon0

20
21
22
23
24
25
26
27
28
29
// If user is dsid user, then return object, else check to ensure
// user fetching data is authorized viewer of uid on dsi document
const { dsid, type } = req.body
const { uid } = req.user
const dsiDoc = await dsiCol.findOne({dsid, type})
const size = bson.calculateObjectSize(dsiDoc)
console.log('docsize: ' + size)
// TODO: check if response doc is valid
if (dsiDoc.uid === uid) {
    res.json(dsiDoc)
fork icon0
star icon0
watch icon0