バージョン 1.4 から非推奨。
定義
パラメーター
$filter: array|object- カウントするドキュメントを指定するフィルター条件。
$options: 配列必要なオプションを指定する配列。
名前タイプ説明collation
array|object
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 では以前のバージョンで使用されていた単純なバイナリ比較によって string が比較されます。
comment
混合
データベースプロファイラ、 currentOp出力、およびログから操作を追跡するのに役立つ任意のコメントを指定できるようにします。
このオプションは MongoDB 4.4 以降で使用可能であり、古いサーバー バージョンで指定すると実行時に例外が発生します。
バージョン1.13の新機能。
hint
string|array|object
使用するインデックス。 インデックス名を string またはインデックス キー パターンをドキュメントとして指定します。 指定すると、クエリ システムはヒント指定したインデックスを使用するプランのみを考慮します。
Changed in version 1.2:
ドキュメントが提供される場合、そのままコマンドに渡されます。以前は、ライブラリはキーパターンをインデックス名に変換していました。
limit
integer
返される一致するドキュメントの最大数。
maxTimeMS
integer
カーソルに対する情報処理操作の累積時間制限(ミリ秒単位)。MongoDB は、割り込みポイントの後の最も早く操作を中止します。
ReadConcern
操作に使用する読み取り保証。 デフォルトはコレクションの読み取り保証 (read concern) です。
トランザクションの一部である個々の操作に対して読み取り保証 (read concern)を指定することはできません。代わりに、トランザクションを開始するときに
readConcernオプションを設定します。readPreference
操作に使用する読み取り設定。 コレクションの読み込み設定(read preference)がデフォルトで設定されます。
セッション
操作に関連付けるクライアント セッション。
バージョン1.3の新機能。
スキップ
integer
結果を返す前にスキップするマッチするドキュメントの数。
Return Values
フィルター条件に一致するドキュメントの数。
エラーと例外
MongoDB\Exception\UnexpectedValueException サーバーからのコマンド応答が不正な形式であった場合、。
MongoDB\Exception\UnsupportedExceptionオプションが使用され、選択したサーバーでサポートされていない場合(例: collation 、 readConcern 、 writeConcern )。
MongoDB\Exception\InvalidArgumentException は、パラメータまたはオプションの解析に関連するエラーの場合は です。
MongoDB$Driver\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.
When evaluating query criteria, MongoDB compares types and values according to its own comparison rules for BSON types, which differs from PHP's comparison and type juggling rules. When matching a special BSON type the query criteria should use the respective BSON class in the extension (e.g. use MongoDB\BSON\ObjectId to match an ObjectId).
その他の参照
カウントコマンドの参照(MongoDB マニュアル)