mongodb - 使用 Quarkus 进行复杂的 mongodb 查询
问题描述
我需要将 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 实现条件查询?
解决方案
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
推荐阅读
- awesome-wm - 如何设置awesome-wm windows颜色
- android - 需要 Android 的 PJSIP 示例
- c# - Zedgraph X 轴平移或缩放 C#
- reactjs - 为什么值不与 value 属性绑定?
- hashicorp-vault - 用户可以在从 github 创建令牌时指定 Vault 的策略吗?
- python - Python plt在for循环中绘图 - 不工作
- android - 如何仅从收件箱中接收来自android中特定号码的短信
- c++ - 使用 std::sort 对矩阵进行排序
- java - 了解 cpu 和 mem SIGAR 输出
- asp.net-mvc - MVC 完整日历错误