sql >> Base de Datos >  >> NoSQL >> MongoDB

Uso de QueryBuilder y BasicDBObjectBuilder en MongoDB 3.3.0 anterior

El segundo argumento del método de búsqueda es el tipo de resultado. Pruebe como se indica a continuación.

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

Actualización para proyección

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

Actualización para añadir filtros

List<Bson> filters = new ArrayList<>();
for (Map.Entry<String, Object> 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<TDocType> docType = dbCollection.find(Filters.and(filters));