Is it possible to order a MongoDB collection by the size of a nested array? Say for example we have a collection of Question documents and each document has a nested array of answers. I want to be able to sort the collection and pull out the most answered questions? I have been looking around and I am not sure its doable directly from MongoDB and I think it would be quite performance intensive to extract all questions and then sort them in Java.
Share
You cann’t query by size of nested collection, you need to create field with size of collection for such needs(mongo db documentation):