How to find documents matching multiple criteria

后端 未结 3 660
滥情空心
滥情空心 2020-12-16 05:19

I\'m trying to query a collection using operands AND\'d together. I\'ve got the shell version working:

db.widgets.find({color: \'black, shape: \'round\', wei         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-16 05:52

    I think the solution above should also work just fine, given the situation I'd suggest the following as an alternative. This is using Criteria

        Query query = new Query();
        List criteriaList = new ArrayList<>();
    Criteria criteriaCreatedBy1 = new Criteria().where("title").is("input");
    criteriaList.add(criteriaCreatedBy1);
    Criteria criteriaCreatedBy2 = new Criteria().where("name").is("name input");
    criteriaList.add(criteriaCreatedBy2);
        query.addCriteria(new Criteria().andOperator(criteriaList.toArray(new Criteria[criteriaList.size()])));
        List getSearchScreens = mongoTemplate.find(query,Screen.class,"collectionName");
    

提交回复
热议问题