사용자 도구

사이트 도구


kb:couchbaseview

Couchbase/View

View 관련 내용들 정리

Map & Reduce

  • MAP
    • emit 함수는 첫번째 인자를 key로, 두번째 인자를 value로서 출력한다. 도큐먼트의 id는 인자로 주지 않아도 id로 출력한다.
  • REDUCE
    • 잘 이해가 안 간다?

Document Metadata

  • id : ID
  • type : Json 문서일 경우는 “json”, 바이너리 데이터일 경우에는 “base64”
  • flags : 데이터 저장시 같이 넘어온 32비트 정수값
  • expiration : 만기 시각. Unix 타임값이라는데 time_t 말하는 건가?

View Parameter

http://docs.couchbase.com/admin/admin/Views/views-querying.html

startkey와 endkey 등은 당연히 찾아야하는 값이 있으니 중요하고, stale 값도 중요하다. 페이징 구현하는 거 아니면, limit 같은 건 딱히 쓸데가 없을 것 같긴 한데…

Parameters Type Description
descending boolean Return the documents in descending by key order.
endkey string Stop returning records when the specified key is reached. Key must be specified as a JSON value.
endkey_docid string Stop returning records when the specified document ID is reached.
full_set boolean Use the full cluster data set (development views only).
group boolean Group the results using the reduce function to a group or single row. Note: Do not use group with group_level because they are not compatible.
group_level numeric Specify the group level to be used. Note: Do not use group_level with group because they are not compatible.
inclusive_end boolean Specifies whether the specified end key is included in the result. Note: Do not use inclusive_end with key or keys.
key string Return only documents that match the specified key. Key must be specified as a JSON value.
keys array Return only documents that match each of keys specified within the given array. Key must be specified as a JSON value. Sorting is not applied when using this option.
limit numeric Limit the number of the returned documents to the specified number.
on_error string Sets the response in the event of an error.
Supported values:

  • continue : Continue to generate view information in the event of an error, including the error information in the view response stream.
  • stop : Stop immediately when an error condition occurs. No further view information is returned.
reduce boolean Use the reduction function.
skip numeric Skip this number of records before starting to return the results.
stale string Allow the results from a stale view to be used.
Supported values:

  • false : The server waits for the indexer to finish the changes that correspond to the current key-value document set and then returns the latest entries from the view index.
  • ok : The server returns the current entries from the index file including the stale views.
  • update_after : The server returns the current entries from the index, and then initiates an index update.
startkey string Return records with a value equal to or greater than the specified key. Key must be specified as a JSON value.
startkey_docid string Return records starting with the specified document ID.

Join

Couchbase에서 JOIN을 시뮬레이트하는 법. 혹은 여러 타입의 문서를 한꺼번에 가져오는 법.

{
    "type" : "post",
    "title" : "Blog post"
    "categories" : [...],
    "author" : "Blog author"
    ...
}
{
    "type" : "comment",
    "post_id" : "post_3454"
    "author" : "Comment author",
    "created_at" : 123498235
...
}

배열을 emit할 수 있다는 걸 자꾸 잊어버린다…

function(doc, meta)
{
    if (doc.post_id && doc.type && doc.type == "post")
    {
        emit([doc.post_id, null], null);
    }
    else if (doc.post_id && doc.created_at && doc.type && doc.type == "comment")
    {
        emit([doc.post_id, doc.created_at], null);
    }
}
kb/couchbaseview.txt · 마지막으로 수정됨: 2015/10/13 21:01 저자 excel96