문서 가져오기
데이터베이스에 있는 모든 문서를 나열하려면 GET로 https://$ACCOUNT.cloudant.com/$DATABASE/_all_docs 요청을 전송하십시오.
_all_docs 엔드포인트에서는 다음과 같은 조회 문자열 및 JSON 본문 인수를 승인합니다.
| 인수 | 설명 | 선택사항 | 유형 | 기본 |
|---|---|---|---|---|
conflicts |
include_docs가 true인 경우에만 설정할 수 있습니다. 각각의 문서에 충돌에 대한 정보를 추가합니다. |
예 | 부울 | 거짓 |
deleted_conflicts |
삭제된 충돌 개정판에 대한 정보를 리턴합니다. | 예 | 부울 | 거짓 |
descending |
키의 내림차순으로 문서를 리턴합니다. | 예 | 부울 | 거짓 |
endkey |
지정된 키에 도달하는 경우 레코드의 리턴을 중지합니다. | 예 | 문자열 | |
endkey_docid |
지정된 문서 ID에 도달하는 경우 레코드의 리턴을 중지합니다. endkey가 설정되지 않은 경우 이 인수를 무시합니다. |
예 | 문자열 | |
include_docs |
리턴에 문서의 전체 컨텐츠를 포함시킵니다. | 예 | 부울 | 거짓 |
inclusive_end |
해당 키가 "endkey" 값과 동일한 행을 포함시킵니다. |
예 | 부울 | 예 |
key |
ID가 지정된 키와 일치하는 문서만 리턴합니다. | 예 | 문자열 | |
keys |
ID가 지정된 키 중 하나와 일치하는 문서만 리턴합니다. | 예 | 문자열 목록 | |
limit |
리턴되는 문서 수를 지정된 숫자로 제한합니다. | 예 | 숫자 | |
meta |
conflicts, deleted_conflicts 및 revs_info의 세 인수에 대한 간단한 조합입니다. meta=true를 사용하는 것은 conflicts=true&deleted_conflicts=true&revs_info=true를 사용하는 것과 동일합니다. |
예 | 부울 | 거짓 |
r |
읽기 쿼럼 값을 지정합니다. | 예 | 숫자 | 2 |
revs_info |
알려진 모든 문서 개정판에 대한 자세한 정보를 포함시킵니다. | 예 | 부울 | 거짓 |
skip |
결과를 리턴하기 전에 이 숫자만큼 레코드를 건너뜁니다. | 예 | 숫자 | 0 |
startkey |
지정된 키로부터 레코드를 리턴합니다. | 예 | 문자열 | |
startkey_docid |
지정된 문서 ID로부터 레코드를 리턴합니다. startkey가 설정되지 않은 경우 이 인수를 무시합니다. |
예 | 문자열 |
_all_docs 엔드포인트의 개념
GET 및 POST $SERVICE_URL/$DATABASE/_all_docs 연산은 IBM Cloudant 데이터베이스의 기본 인덱스, 즉 각 문서의 _id 를 순서대로 정리해 둔 인덱스에서 데이터를 가져옵니다. _all_docs 엔드포인트는 요청할 데이터의 범위와 각 문서의 본문을 반환할지 여부를
구성하는 여러 가지 선택적 매개변수를 받습니다. 매개변수가 지정되지 않은 경우, _all_docs 는 데이터베이스의 모든 문서를 스트리밍하며, _id 문서와 현재 _rev 토큰만 반환합니다.
페이지 매김
모든 문서에 키 기반 페이지 매김을 사용하세요. 구체적인 세부 사항과 예는 모든 문서의 페이징에 대한 API 문서 항목을 참조하세요.
참고
-
include_docs=true를 사용하는 경우 성능상 영향이 발생할 수 있습니다. -
keys인수 사용 시 원하는 키를 나열하기 위해 복수의 문자열이 필요한 경우POST요청이 아닌GET요청을 전송하는 것이 더 간단할 수 있습니다. -
keys인수 사용 시 개정판이 삭제된 경우 리턴되는value속성은 문서의 현재_rev및_deleted속성이 포함된 JSON 오브젝트입니다.doc속성은 요청에서include_docs=true를 지정한 경우에만 채워지며 문서가 삭제된 경우null입니다.
다음과 같이 HTTP를 사용하여 데이터베이스에 있는 모든 문서를 나열하는 예제를 참조하십시오.
GET /_all_docs HTTP/1.1
데이터베이스의 모든 문서를 나열하려면 다음 예제를 참조하십시오.
curl -H "Authorization: Bearer $API_BEARER_TOKEN" -X POST "$SERVICE_URL/orders/_all_docs" -H "Content-Type: application/json" --data '{ "include_docs": true, "startkey": "abc", "limit": 10}'
import com.ibm.cloud.cloudant.v1.Cloudant;
import com.ibm.cloud.cloudant.v1.model.AllDocsResult;
import com.ibm.cloud.cloudant.v1.model.PostAllDocsOptions;
Cloudant service = Cloudant.newInstance();
PostAllDocsOptions docsOptions =
new PostAllDocsOptions.Builder()
.db("orders")
.includeDocs(true)
.startKey("abc")
.limit(10)
.build();
AllDocsResult response =
service.postAllDocs(docsOptions).execute().getResult();
System.out.println(response);
const { CloudantV1 } = require('@ibm-cloud/cloudant');
const service = CloudantV1.newInstance({});
service.postAllDocs({
db: 'orders',
includeDocs: true,
startKey: 'abc',
limit: 10
}).then(response => {
console.log(response.result);
});
from ibmcloudant.cloudant_v1 import CloudantV1
service = CloudantV1.new_instance()
response = service.post_all_docs(
db='orders',
include_docs=True,
start_key='abc',
limit=10
).get_result()
print(response)
postAllDocsOptions := service.NewPostAllDocsOptions(
"orders",
)
postAllDocsOptions.SetIncludeDocs(true)
postAllDocsOptions.SetStartKey("abc")
postAllDocsOptions.SetLimit(10)
allDocsResult, response, err := service.PostAllDocs(postAllDocsOptions)
if err != nil {
panic(err)
}
b, _ := json.MarshalIndent(allDocsResult, "", " ")
fmt.Println(string(b))
이전 Go 예제에서는 다음 가져오기 블록이 필요합니다.
import (
"encoding/json"
"fmt"
"github.com/IBM/cloudant-go-sdk/cloudantv1"
)
모든 Go 예제에서는 service 오브젝트가 초기화되어야 합니다. 자세한 정보는 API 문서 인증 섹션 예제를 참조하십시오.
다음과 같이 HTTP를 사용하여 지정된 키 중 하나 이상과 일치하는 데이터베이스에 있는 모든 문서를 나열하는 예제를 참조하십시오.
GET /_all_docs?keys=["somekey","someotherkey"] HTTP/1.1
지정된 키 중 하나 이상과 일치하는 데이터베이스의 모든 문서를 나열하려면 다음 예제를 참조하십시오.
curl -H "Authorization: Bearer $API_BEARER_TOKEN" -X POST "$SERVICE_URL/orders/_all_docs" -H "Content-Type: application/json" --data '{
"include_docs": true,
"keys": ["somekey", "someotherkey"],
"limit": 10
}'
import com.ibm.cloud.cloudant.v1.Cloudant;
import com.ibm.cloud.cloudant.v1.model.AllDocsResult;
import com.ibm.cloud.cloudant.v1.model.PostAllDocsOptions;
import java.util.Arrays;
Cloudant service = Cloudant.newInstance();
PostAllDocsOptions docsOptions =
new PostAllDocsOptions.Builder()
.db("orders")
.includeDocs(true)
.keys(Arrays.asList("somekey", "someotherkey"))
.limit(10)
.build();
AllDocsResult response =
service.postAllDocs(docsOptions).execute().getResult();
System.out.println(response);
const { CloudantV1 } = require('@ibm-cloud/cloudant');
const service = CloudantV1.newInstance({});
service.postAllDocs({
db: 'orders',
includeDocs: true,
keys: ['somekey', 'someotherkey'],
limit: 10
}).then(response => {
console.log(response.result);
});
from ibmcloudant.cloudant_v1 import CloudantV1
service = CloudantV1.new_instance()
response = service.post_all_docs(
db='orders',
include_docs=True,
keys=['somekey', 'someotherkey'],
limit=10
).get_result()
print(response)
postAllDocsOptions := service.NewPostAllDocsOptions(
"orders",
)
postAllDocsOptions.SetIncludeDocs(true)
postAllDocsOptions.SetKeys([]string{"somekey", "someotherkey"})
postAllDocsOptions.SetLimit(10)
allDocsResult, response, err := service.PostAllDocs(postAllDocsOptions)
if err != nil {
panic(err)
}
b, _ := json.MarshalIndent(allDocsResult, "", " ")
fmt.Println(string(b))
이전 Go 예제에서는 다음 가져오기 블록이 필요합니다.
import (
"encoding/json"
"fmt"
"github.com/IBM/cloudant-go-sdk/cloudantv1"
)
모든 Go 예제에서는 service 오브젝트가 초기화되어야 합니다. 자세한 정보는 API 문서 인증 섹션 예제를 참조하십시오.
응답은 매개변수와 일치하는 데이터베이스에 있는 모든 문서가 포함된 JSON 오브젝트입니다. 다음 표에서는 개별 필드의 의미에 대해 설명합니다.
| 필드 | 설명 | 유형 |
|---|---|---|
offset |
문서 목록이 시작된 오프셋입니다. | 숫자, 널(null가 지정된 경우 유형이 keys이 될 수 있습니다.) |
rows |
문서 오브젝트의 배열입니다. | 배열 |
total_rows |
조회의 매개변수와 일치하는 데이터베이스 또는 보기의 문서 수입니다. | 숫자 |
pdate_seq |
데이터베이스의 현재 업데이트 순서입니다. | 문자열 |
다음과 같이 데이터베이스에 있는 모든 문서에 대한 요청 이후의 응답 예제를 참조하십시오.
{
"total_rows": 3,
"offset": 0,
"rows": [
{
"id": "5a049246-179f-42ad-87ac-8f080426c17c",
"key": "5a049246-179f-42ad-87ac-8f080426c17c",
"value": {
"rev": "2-9d5401898196997853b5ac4163857a29"
}
},
{
"id": "96f898f0-f6ff-4a9b-aac4-503992f31b01",
"key": "96f898f0-f6ff-4a9b-aac4-503992f31b01",
"value": {
"rev": "2-ff7b85665c4c297838963c80ecf481a3"
}
},
{
"id": "d1f61e66-7708-4da6-aa05-7cbc33b44b7e",
"key": "d1f61e66-7708-4da6-aa05-7cbc33b44b7e",
"value": {
"rev": "2-cbdef49ef3ddc127eff86350844a6108"
}
}
]
}