0
더 빠른 계산 방법에 대한 질문이 있습니다. filterParameters라는 필터 매개 변수가 있습니다. 지금은 일을 : Mongo가 콜렉션에서 카운트하거나 커서로 계산합니다. 어느 것이 더 빠릅니다.
1. First option:
int count = count with db.dbCollection.count(filterParameters)
and then
dbCursor = db.dbCollection.find(filterParameters).skip(..).limit(..)
2. Second way:
dbCursor = db.dbCollection.find(filterParameters).skip(..).limit(..)
int count = dbCursor.count()
그리고 자바
, 첫 번째 방법 :Integer countAllItems = documentService.count(documentType,filterQuery)
DBCursor documents = documentService.list(documentType, [:], filterQuery, sortQuery, command.start, command.count)
여기서 documentService.count(documentType,filterQuery)
일 :
def collection = db.getCollection(documentType.collectionName)
collection.count(filterQuery)
및 documentService.list에만 컬렉션 찾을 수있다.
그리고 두 번째 방법 : 빠른 방법은
DBCursor documents = documentService.list(documentType, [:], filterQuery, sortQuery, command.start, command.count)
Integer countAllItems = documents.count()
하나?
그러면 두 번째 속도가 빨라야합니까? 실제로'count' 쿼리가'find' + 커서 카운트 (즉 "두 번째 방법")와 같다고 말하면 "첫 번째 옵션"은 두 번째 + 다른 find 쿼리와 동일합니다. 또는 나는 어딘가에서 착각하고 있는가? 게다가, 몽고는 실행 된 쿼리를 이용하지 않습니까? – dgiugg
그래서 나는 java 드라이버의 첫 번째 옵션에서 홀 옵션을 두 번째 옵션보다 짧게 사용했기 때문에 실제적인 차이가 나타납니다. – lukisp
@ dgiugg 아니오, 두 방법 모두 하나의 쿼리 만 수행 – Sammaye