Collection::replaceOne
(사용 가능한 버전 정보가 없으며 Git에만 있을 수 있음)
Collection::replaceOne — 하나의 컬렉션 문서 바꾸기
설명
public mysql_xdevapi\Collection::replaceOne(string $id
, string $doc
): mysql_xdevapi\Result
존재하는 경우 ID로 식별되는 문서를 업데이트(또는 대체)합니다.
- 단일 문서를 JSON 문자열로 추가합니다.
- 단일 문서를 배열로 추가:
[ 'field' => 'value', 'field2' => 'value2' ... ]
- 동일한 작업에서 두 문서를 혼합하여 여러 문서를 추가할 수 있습니다.
매개변수
id
- 바꾸거나 업데이트할 문서의 ID입니다. 일반적으로 이것은 레코드가 추가될 때 MySQL 서버에 의해 생성된 _id입니다.
doc
- id 매개변수와 일치하는 문서를 업데이트하거나 교체할 컬렉션 문서입니다.
이 문서는 문서 객체이거나 새 문서를 설명하는 유효한 JSON 문자열일 수 있습니다.
반환 값
영향을 받는 항목 수와 작업에 의해 생성된 경고 수를 쿼리하는 데 사용할 수 있는 Result 개체입니다.
Examples
예제 #1 mysql_xdevapi\Collection::replaceOne() 예제
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$schema = $session->getSchema("addressbook");
$collection = $schema->createCollection("people");
$result = $collection->add('{"name": "Alfred", "age": 18, "job": "Butler"}')->execute();
// Normally the _id is known by other means,
// but for this example let's fetch the generated id and use it
$ids = $result->getGeneratedIds();
$alfred_id = $ids[0];
// ...
$alfred = $collection->getOne($alfred_id);
$alfred['age'] = 81;
$alfred['job'] = 'Guru';
$collection->replaceOne($alfred_id, $alfred);
?>