버전 1.4부터 더 이상 사용되지 않습니다.
정의
매개변수
$filter: 배열|객체- 계산할 문서를 지정하는 필터 기준입니다.
$options: 배열원하는 옵션을 지정하는 배열입니다.
이름유형설명데이터 정렬
배열|객체
Collation allows users to specify language-specific rules for string comparison, such as rules for lettercase and accent marks. When specifying collation, the
localefield is mandatory; all other collation fields are optional. For descriptions of the fields, see Collation Document.데이터 정렬이 지정되지 않았지만 컬렉션에 기본 데이터 정렬이 있는 경우, 작업은 컬렉션에 지정된 데이터 정렬을 사용합니다. 컬렉션 또는 연산에 대한 데이터 정렬이 지정되지 않은 경우, MongoDB는 이전 버전에서 문자열 비교에 사용된 간단한 이진 비교를 사용합니다.
comment
혼합
사용자가 데이터베이스 프로파일러, currentOp 출력 및 로그를 통해 작업을 추적하는 데 도움이 되는 임의의 주석을 지정할 수 있습니다.
이 옵션은 MongoDB 4.4부터 사용할 수 있으며 이전 서버 버전에 대해 지정된 경우 실행 시 예외가 발생합니다.
버전 1.13에 추가 되었습니다.
hint
문자열|배열|객체
사용할 인덱스입니다. 인덱스 이름을 문자열로 지정하거나 인덱스 키 패턴을 문서로 지정합니다. 이 옵션을 지정하면 쿼리 시스템은 힌트 인덱스를 사용하는 계획만 고려합니다.
1.2 버전에서 변경됨:
문서가 제공되면 명령에 그대로 전달됩니다. 이전에는 라이브러리가 키 패턴을 인덱스 이름으로 변환했습니다.
limit
integer
반환할 일치 문서의 최대 개수입니다.
최대 시간 (MS)
integer
커서에서 작업을 처리하는 데 걸리는 누적 시간 제한(밀리초)입니다. MongoDB는 가장 빠른 다음 MongoDB는 중단 지점 이후 가장 빠른 시점에 작업을 중단합니다.
readConcern
읽기 설정
작업에 사용할 읽기 설정입니다. 기본값은 컬렉션의 읽기 설정입니다.
Session
작업과 연결할 클라이언트 세션입니다.
버전 1.3에 추가 되었습니다.
건너뛰기
integer
결과를 반환하기 전에 건너뛸 일치하는 문서의 수입니다.
Return Values
필터 기준과 일치하는 문서 수입니다.
오류/예외
MongoDB\Exception\UnexpectedValueException 서버의 명령 응답이 잘못된 경우입니다.
옵션이 사용되지만 선택한 서버에서 지원되지 않는 경우 MongoDB\Exception\UnsupportedException입니다(예: collation, readConcern, writeConcern).
MongoDB\Exception\InvalidArgumentException 매개변수 또는 옵션의 구문 분석과 관련된 오류의 경우입니다.
확장 수준의 기타 오류에 대한MongoDB\ 드라이버\Exception\RuntimeException (예: 연결 오류).
행동
This method is deprecated and cannot be executed within a transaction. It has always been implemented using the count command. The behavior of the count command differs depending on the options passed to it and may or may not provide an accurate count. When no query filter is provided, the count command provides an estimate using collection metadata. Even when provided with a query filter the count command can return inaccurate results with a sharded cluster if orphaned documents exist or if a chunk migration is in progress. The MongoDB\Collection::countDocuments() method avoids these sharded cluster problems entirely.
쿼리 기준을 평가할 때 MongoDB BSON types에 대한 자체 비교 규칙에 따라 유형과 값을 비교하며, 이는 PHP의 비교 및 유형 저글링 규칙과 다릅니다. 특수 BSON types와 일치하는 경우 쿼리 기준은 확장에서 해당 BSON 클래스를 사용해야 합니다(예: MongoDB\BSON\ObjectId 를 사용하여 ObjectId와 일치시킵니다).
다음도 참조하세요.
MongoDB 매뉴얼의 count 명령 참조