Puede actualizar el método a continuación. Está intentando proporcionar múltiples $and
operador con cada uno teniendo un criterio.
Por cierto, no necesitas un and
explícito ing como mongodb proporciona and
implícitos ing cuando los criterios están separados por comas.
public void getFile(Map<String, Object> metaData) throws Exception {
Criteria criteria = new Criteria();
metaData.forEach((k, v) -> criteria.and("metadata." + k).is(v));
GridFSDBFile gridFSDBFile = gridFsOperations.findOne(new Query(criteria));
if (gridFSDBFile == null) {
throw new HttpConflictException();
}
En los casos en que necesite and
explícitos ing, puede usar el siguiente código
public void getFile(Map<String, Object> metaData) throws Exception {
Criteria criteria = new Criteria();
Criteria[] andExpressions = metaData.entrySet().stream().
map(kv -> Criteria.where("data." + kv.getKey()).is(kv.getValue()))
.toArray(Criteria[]::new);
Query andQuery = new Query();
Criteria andCriteria = new Criteria();
andQuery.addCriteria(andCriteria.andOperator(andExpressions));
GridFSDBFile gridFSDBFile = gridFsOperations.findOne(andQuery);
if (gridFSDBFile == null) {
throw new HttpConflictException();
}