0

I have searched and was not able to find a solution to this. The closest thing I found was

Object.bsonsize(db.test.findOne({type:"auto"}))

which is JavaScript not Java.

Jee Mok
  • 6,157
  • 8
  • 47
  • 80
  • You can get the **Average Object Size** in a collection, using [db.collections.stats()](https://docs.mongodb.com/manual/reference/method/db.collection.stats/index.html). The same command can be executed from Java code and get the average object size. – prasad_ Oct 15 '19 at 02:49

1 Answers1

0

I don't use the java client, but you should be able to use it to execute your raw JavaScript. Here's a link which suggests how:

How do I execute a MongoDB js script using the Java MongoDriver

Ian Newson
  • 7,679
  • 2
  • 47
  • 80