I am looking for a way to get the collection size of a mongoDB collection in nodeJS including the indexes.
Is there any way to calculate the size of a collection (preferebly after a .find()
statement to get the size of a part of the collection) in nodejs?
I can only run the db.stats()
which returns the stats of the whole database, as soon as I try running it on a collection: db.collection('Documents')
I get an error.
Running db.collection('Documents').totalSize()
only gives an error saying it is not defined.
I have also tried the bson package, which only returns the size of files themselves, not the indexes:
const documentCollection = await db.collection('Documents').find({owner: userId}).toArray()
const size = BSON.calculateObjectSize(documentCollection)
pacman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.