6

I need to migrate a Spring Boot project to Quarkus. The project has been using Spring Data Mongodb for all the queries. Now I find it difficult to migrate complex queries.

One example is

public List<MyData> findInProgressData(MyConditions conditions) {
    Query mongoQuery = new Query();

    mongoQuery.addCriteria(Criteria.where("status").is(IN_PROGRESS));
    mongoQuery.addCriteria(Criteria.where("location").is(conditions.getLocationCode()));

    if (StringUtils.isNotBlank(conditions.getType())) {
        mongoQuery.addCriteria(Criteria.where("type").is(conditions.getType()));
    }

    if (StringUtils.isNotBlank(conditions.getUserId())) {
        mongoQuery.addCriteria(Criteria.where("userId").is(conditions.getUserId()));
    }

    mongoQuery.with(Sort.by(Sort.Direction.ASC, "createdAt"));

    return mongoTemplate.find(mongoQuery, MyData.class);
}

How can I implement the conditional query with Quarkus?

1 Answers1

2

You can probably try Panache with Mongodb. You can pass Document into .find() method, In this object you can specify any criteria.

        final Document document = new Document();
        document.put("status","IN_PROGRESS");
        ...
        result = MyData.find(document); // or MyDataRepository

But you'll need to adapt some of the code to Panache, which can be done either via extending PanacheEntity or PanacheEntityBase

Dmytro Chaban
  • 1,106
  • 1
  • 11
  • 19