I need to write a Query which can find objects in DB whose child array size is greater than something.
My Object looks like:
{
"_id" : ObjectId("sbg8732god78"),
"studentIds" : [ "d3782gdo", "d8o3g7" ]
...
}
I need to find all objects with studentIds
array size greater than n
. I was looking at available methods like:
Query query = new Query();
query.addCriteria(Criteria.where("studentIds").exists(true));
query.addCriteria(Criteria.where("studentIds").size().gt(0));
But size()
method accepts an integer. How can this be done?