我在 Google Cloud Firestore 中遇到了查询条件的问题。
有人能帮助我吗?
以下是获取以 HA_ 开头并按 ID 倒序排列的第一个文档的代码:
public Article getLastArticleProvider() {
ApiFuture<QuerySnapshot> query = firebaseDB.getTblArticles()
.whereGreaterThanOrEqualTo("articleId", "HA_")
.orderBy("id", Query.Direction.DESCENDING)
.limit(1)
.get();
QuerySnapshot snapshotApiFuture;
Article article = null;
try {
snapshotApiFuture = query.get();
List<QueryDocumentSnapshot> documents = snapshotApiFuture.getDocuments();
for (QueryDocumentSnapshot document : documents) {
article = document.toObject(Article.class);
}
} catch (InterruptedException | ExecutionException e) {
return null;
}
return article;
}
我想获取文章ID以“HA_”或“XE_”开头的最后一篇文章的ID。
例如上图:
- 如果文章ID以“HA_”开头,则返回ID为831的对象
- 如果文章ID以“XE_”开头,则返回ID为833的对象
现在我遇到了一个错误:
java.util.concurrent.ExecutionException: com.google.api.gax.rpc.InvalidArgumentException: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: inequality filter property and first sort order must be the same: articleId and id