문서 탐색 열기
R2D1 / 문서

쿼리

R2D1은 derived index를 먼저 조회한 다음 authoritative DocumentStore에서 matching document를 hydrate합니다. document content를 scan해서 application memory에서 filter하지 않습니다.

Indexed field 필터

where(String)로 비교를 시작합니다. field는 @Index가 붙어 있어야 하고 adapter가 해당 value type을 지원해야 합니다.

Page<User> page =
    users.query()
        .where("country")
        .eq("NZ")
        .sortBy("score", SortDirection.DESC)
        .limit(20)
        .fetch();

지원 비교 연산자

모든 filter는 논리적 AND로 결합됩니다. JDBC 기본 contract에서 Boolean field는 equality와 inequality를 지원하고 ordered comparison은 ordered value type을 요구합니다.

Method의미
eq(value)같음
notEq(value)같지 않음
gt(value)보다 큼
gte(value)크거나 같음
lt(value)보다 작음
lte(value)작거나 같음

단일 sort

sortBy는 최대 한 번 호출합니다. sort field도 @Index가 필요하며 명시적인 limit은 양수여야 합니다.

Page<User> page = users.query()
    .where("country").eq("NZ")
    .sortBy("score", SortDirection.DESC)
    .limit(20)
    .fetch();

Cursor pagination

fetch()는 Page<T>를 반환하고 nextCursor는 다음 페이지가 있을 때 non-null입니다. after(...)를 사용할 때 같은 filter와 sort를 유지하세요. cursor는 adapter-specific opaque token이며 decode하거나 수정하지 마세요.

Page<User> first = users.query()
    .sortBy("score", SortDirection.DESC)
    .limit(20)
    .fetch();

if (first.nextCursor() != null) {
  Page<User> next = users.query()
      .sortBy("score", SortDirection.DESC)
      .limit(20)
      .after(first.nextCursor())
      .fetch();
}

의도적인 한계

  • 제공하지 않음: join, aggregation, arbitrary SQL, OR predicate, full-text search, LIKE, contains, 정규식
  • query에 참여하는 field는 document metadata에서 @Index로 선언해야 합니다.
  • adapter가 지원하지 않는 type이나 unindexed field는 검증 단계에서 거부됩니다.