I am trying to create dynamic query with user input with and operation My code is I created List of criteria like:
List<Criteria> criterias = new ArrayList<Criteria>();
and added criteria to this list.And its getting added successfully. now I want to make and operator between each criteria.
Criteria criteria = new Criteria().andOperator(criterias.get(0), criterias.get(1));
It works fine But my input is not fixed so I want it should added dynamically, I tried like
for(int i=0;i<criterias.size();i++)
Criteria criteria = new Criteria().andOperator(criterias.get(i));
where I am missing?
To unite all criterias from a list of criterias by "$and" operator :
Criteria criteria = new Criteria().andOperator(criterias.toArray(new Criteria[criterias.size()]));
here is docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With