컬렉션에 중복이 있는지 확인하려고합니다. 저장 프로 시저 및 Azure 데이터베이스를 처음 사용하므로 지금은 고유 한 항목을 계산하려고합니다. count distinct (column name) = count (column name)이면 중복이 없으므로 저장 프로 시저를 작성하려고합니다. 그러나 azure는 한 번에 100 개의 문서 만 검색합니다. 사용 가능한 모든 배치에 대한 개수가 필요합니다.
고유 한 항목의 수를 가져올 수 있었지만 검색된 첫 번째 배치의 수 (100 개)를 보여줍니다. 모든 배치에 대한 수가 필요합니다.
function sample(prefix) {
var collection = getContext().getCollection();
var isAccepted = collection.queryDocuments(
collection.getSelfLink(),
'SELECT DISTINCT VALUE r.column FROM root r',
function (err, feed, options) {
if (err) throw err;
if (!feed || !feed.length) {
var response = getContext().getResponse();
response.setBody('no docs found');
}
else {
var response = getContext().getResponse();
response.setBody(JSON.stringify(feed.length));
}
});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}
출력이 컬렉션의 고유 항목을 계산할 것으로 예상합니다. 103이어야하지만 실제 값은 azure가 한 번에 검색 한 숫자 인 100입니다.
queryDocuments에 대한 FeedOptions pageSize 속성의 기본값은 100이며 문제의 원인 일 수 있습니다. 값을 -1로 설정하십시오. 다음 저장 프로시 저는 내 쪽에서 잘 작동합니다. 참조하십시오.
function getall(){
var context = getContext();
var response = context.getResponse();
var collection = context.getCollection();
var collectionLink = collection.getSelfLink();
var filterQuery = 'SELECT * FROM c';
collection.queryDocuments(collectionLink, filterQuery, {pageSize:-1 },
function(err, documents) {
response.setBody(response.getBody() + JSON.stringify(documents));
}
);
}
도움이 되었기를 바랍니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다