Skip to content
Advertisement

MongoDB how to count array elements with Java driver

I need my application to count the size of an array foos inside a document using Java driver 3.8. I know I can do this with the shell

JavaScript

but I have no idea of how to do this with java, because the only method producing a $size operator I found is Filters.size(String fieldName, int size) that is meant to look for documents where array fieldName has size size. I searched inside com.mongodb.client.model package but I found nothing to answer my question.

Advertisement

Answer

No there are no helpers in java driver to help with aggregation expression for $project stage.

Try

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement