我最近开始使用 couchbase。我正在使用 Spring-Data couchbase 在 Couchbase 中插入 Java POJO。由于 Spring Data Couchbase 项目不支持分页和排序,我尝试使用 couchbase java client 2.2.0-dp2。
我插入了 8 个用户,其 id 范围从 1 到 8。
我编写了以下代码来应用分页和排序。
public void test() {
int offset = 5 * (1 - 1);
Statement statement = select("*").from("test").where(x("_class").eq(s("com.test.rest.entity.User"))).orderBy(Sort.asc("id")).limit(5).offset(offset);
log.info(statement.toString());
Iterator<QueryRow> result = bucket.query(Query.simple(statement)).rows();
while(result.hasNext()) {
QueryRow doc = result.next();
log.info("Document:: " + doc.value());
}
}
但是,我看到的结果如下。它应该是 test1 到 test5,尽管用户是随机选择的。有人可以帮我吗?
Document:: {“test":{"createdAt":1.443420400374E12,"firstname":"test5","_class":"com.test.rest.entity.User","type":"User","lastname":"test5"}}
Document:: {“test":{"createdAt":1.443420708495E12,"firstname":"test8","_class":"com.test.rest.entity.User","type":"User","lastname":"test8"}}
Document:: {“test:{"createdAt":1.443420386638E12,"firstname":"test2","_class":"com.test.rest.entity.User","type":"User","lastname":"test2"}}
Document:: {“test":{"createdAt":1.443420704104E12,"firstname":"test7","_class":"com.test.rest.entity.User","type":"User","lastname":"test7"}}
Document:: {“test":{"createdAt":1.443420379712E12,"firstname":"test1","_class":"com.test.rest.entity.User","type":"User","lastname":"test1"}}