6

我需要将 Spring Boot 项目迁移到 Quarkus。该项目一直使用 Spring Data Mongodb 进行所有查询。现在我发现很难迁移复杂的查询。

一个例子是

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);
}

如何使用 Quarkus 实现条件查询?

4

1 回答 1

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

于 2020-05-02T09:46:44.963 回答