Collection::removeOne

(사용 가능한 버전 정보가 없으며 Git에만 있을 수 있음)

Collection::removeOne — 하나의 컬렉션 문서 제거


설명

public mysql_xdevapi\Collection::removeOne(string $id): mysql_xdevapi\Result

해당 ID가 있는 컬렉션에서 문서 하나를 제거합니다. Collection.remove("_id = :id").bind("id", id).execute()의 단축키입니다.


매개변수

id
제거할 컬렉션 문서의 ID입니다. 일반적으로 이것은 레코드가 추가될 때 MySQL 서버에 의해 생성된 _id입니다.

반환 값

영향을 받는 항목 수 또는 작업에 의해 생성된 경고 수를 쿼리하는 데 사용할 수 있는 Result 개체입니다.


Examples

예제 #1 mysql_xdevapi\Collection::removeOne() 예제

                  
<?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];

$result = $collection->removeOne($alfred_id);

if(!$result->getAffectedItemsCount()) {
    echo "Alfred with id $alfred_id was not removed.";
} else {
    echo "Goodbye, Alfred, you can take _id $alfred_id with you.";
}
?>
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

Goodbye, Alfred, you can take _id 00005b6b536100000000000000cb with you.