QueryBuilder and BasicDBObjectBuilder usage in MongoDB 3.3.0 above

前端 未结 1 1614
旧时难觅i
旧时难觅i 2021-01-27 19:09

PART 1

Following up solutions to Querying Mongo Collection using QueryBuilder in Mongo 3.3.0 , I tried implementing the suggested methods to im

1条回答
  •  旧巷少年郎
    2021-01-27 19:47

    The second argument of find method is result type. Try as below.

    FindIterable tDocTypeList = dbCollection.find(filter, TDocType.class);
    

    Update for projection

    FindIterable tDocTypeList = dbCollection.find(filter, TDocType.class).projection(outputQuery);
    

    Update for appending filters

    List filters = new ArrayList<>();
    for (Map.Entry entry : query.getParams().entrySet()) {
            // this is where its building the query
       if (some condition){
           filters.add(Filters.eq(entry.getKey(), entry.getValue()));
       }
       if (some other condition){
           filters.add(Filters.in(entry.getKey(), query.getValues()));
       }
    }
    FindIterable docType = dbCollection.find(Filters.and(filters));
    

    0 讨论(0)
提交回复
热议问题