AI 에이전트의 경우: 문서 인덱스는 https://www.mongodb.com/ko-kr/docs/llms.txt에서 사용할 수 있으며, 모든 페이지의 마크다운 버전은 어떤 URL 경로에 .md를 추가하여 사용할 수 있습니다.
Docs Menu

MongoDB\Database::command()

MongoDB\Database::command()

데이터베이스에서 명령 을 실행합니다. 이는 일반적으로 라이브러리 내에 해당 헬퍼 메서드가 없는 명령을 실행하는 데 사용됩니다.

function command(
array|object $command,
array $options = []
): MongoDB\Driver\Cursor
$command : 배열|객체
데이터베이스 명령 문서.
$options : 배열

원하는 옵션을 지정하는 배열입니다.

이름
유형
설명

읽기 설정

작업에 사용할 읽기 설정 입니다. 기본값은 데이터베이스의 읽기 설정입니다.

Session

작업과 연결할 클라이언트 세션입니다.

버전 1.3에 추가 되었습니다.

typeMap

배열

커서에 적용 할 유형 맵에 따라 BSON 문서가 PHP 값으로 변환되는 방식이 결정됩니다. 기본값은 데이터베이스의 유형 맵입니다.

MongoDB\ 드라이버\Cursor 객체.

MongoDB\Exception\InvalidArgumentException 매개변수 또는 옵션의 구문 분석과 관련된 오류의 경우입니다.

확장 수준의 기타 오류에 대한MongoDB\ 드라이버\Exception\RuntimeException (예: 연결 오류).

대부분의 데이터베이스 명령은 단일 결과 문서 를 반환하며, 이는 반환된 커서 를 배열 로 변환하고 첫 번째 요소에 액세스하여 얻을 수 있습니다. 다음 예시 에서는 명령을 실행하고 결과 문서 를 출력합니다.

<?php
$database = (new MongoDB\Client)->test;
$cursor = $database->command(['ping' => 1]);
var_dump($cursor->toArray()[0]);

출력은 다음과 유사합니다:

object(MongoDB\Model\BSONDocument)#11 (1) {
["storage":"ArrayObject":private]=>
array(1) {
["ok"]=>
float(1)
}
}

Some database commands return a cursor with multiple results. The following example executes listCollections, which returns a cursor containing a result document for each collection in the test database. Note that this example is illustrative; applications would generally use MongoDB\Database::listCollections() in practice.

<?php
$database = (new MongoDB\Client)->test;
$cursor = $database->command(['listCollections' => 1]);
var_dump($cursor->toArray());

출력은 다음과 유사합니다:

array(3) {
[0]=>
object(MongoDB\Model\BSONDocument)#11 (1) {
["storage":"ArrayObject":private]=>
array(2) {
["name"]=>
string(11) "restaurants"
["options"]=>
object(MongoDB\Model\BSONDocument)#3 (1) {
["storage":"ArrayObject":private]=>
array(0) {
}
}
}
}
[1]=>
object(MongoDB\Model\BSONDocument)#13 (1) {
["storage":"ArrayObject":private]=>
array(2) {
["name"]=>
string(5) "users"
["options"]=>
object(MongoDB\Model\BSONDocument)#12 (1) {
["storage":"ArrayObject":private]=>
array(0) {
}
}
}
}
[2]=>
object(MongoDB\Model\BSONDocument)#15 (1) {
["storage":"ArrayObject":private]=>
array(2) {
["name"]=>
string(6) "restos"
["options"]=>
object(MongoDB\Model\BSONDocument)#14 (1) {
["storage":"ArrayObject":private]=>
array(0) {
}
}
}
}
}