기본적으로 수행하는 쿼리는 정상적인 결과로 제한됩니다. RavenDB는 기본적으로 안전하고 수백만 건의 레코드를 스트리밍하지 않을 것이라고 약속합니다. yoru 데이터베이스에 특정 형식의 문서의 수를 얻기 위하여
, 당신은 누구의 작업은 각 문서 유형의 수를 추적하는 특별한지도-감소 인덱스가 필요합니다. 인덱스 거래의이 유형은 직접 문서 메타 데이터와 함께, 대신 코드로 만들려고의 까마귀 스튜디오에서이를 정의하는 것이 더 쉽습니다 때문입니다.
해당 인덱스의 소스는 this question에 있지만 여기에 복사합니다 :
다음
// Index Name: Raven/DocumentCollections
// Map Query
from doc in docs
let Name = doc["@metadata"]["Raven-Entity-Name"]
where Name != null
select new { Name , Count = 1}
// Reduce Query
from result in results
group result by result.Name into g
select new { Name = g.Key, Count = g.Sum(x=>x.Count) }
코드에 액세스 할 수 모두에 의해 생성 된 익명 형의 구조를 모방하는 클래스를 필요 지도 및 감소 쿼리 :
0 : Ayende가
previously linked question에 대한 답변에서 노트로
public class Collection
{
public string Name { get; set; }
public int Count { get; set; }
}
그런 다음,이 같은 인덱스에서 결과를 얻을 수 있습니다
123,379,은 대량 삽입 문서의 무리, 인덱스가 부실 할 수있다 그래서 후에 인덱스가 비동기 적으로 업데이트되는 점을 염두에 두셔야합니다. 당신은 .Query(...)
후 .Customize(x => x.WaitForNonStaleResults())
권리를 추가하여 대기하도록 강제 할 수 있습니다.
Raven Studio는 실제로 모든 데이터베이스에 존재하는 인덱스 Raven/DocumentsByEntityName
에서이 데이터를 얻습니다. 일반 쿼리를 생략하고 인덱스에 메타 데이터를 가져옵니다. 이 같은 것을 에뮬레이션 할 수 있습니다 : QueryResult는 유용한 데이터를 많이 포함
QueryResult result = docStore.DatabaseCommands.Query("Raven/DocumentsByEntityName",
new Raven.Abstractions.Data.IndexQuery
{
Query = "Tag:MyDocument",
PageSize = 0
},
includes: null,
metadataOnly: true);
var totalDocsOfType = result.TotalResults;
:
{
Results: [ ],
Includes: [ ],
IsStale: false,
IndexTimestamp: "2013-11-08T15:51:25.6463491Z",
TotalResults: 3,
SkippedResults: 0,
IndexName: "Raven/DocumentsByEntityName",
IndexEtag: "01000000-0000-0040-0000-00000000000B",
ResultEtag: "BA222B85-627A-FABE-DC7C-3CBC968124DE",
Highlightings: { },
NonAuthoritativeInformation: false,
LastQueryTime: "2014-02-06T18:12:56.1990451Z",
DurationMilliseconds: 1
}
통계를 요청하는 경우가 많은이처럼, 당신은 어떤 쿼리를 얻을 동일한 데이터입니다 :
RavenQueryStatistics stats;
Session.Query<Course>()
.Statistics(out stats)
// Rest of query
그렇다면 레이븐 스튜디오는 색인없이 문서 수를 올바르게보고 할 수 있습니까? – mll5
레이븐 스튜디오 내부 표준 LINQ 기반 쿼리 의미 밖에서, 레이븐/DocumentsByEntityName 지수에 대한 통계를 사용하고 있습니다. 내 대답을 업데이트 할게. –