CollectionModify::arrayAppend

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

CollectionModify::arrayAppend — 배열 필드에 요소 추가


설명

public mysql_xdevapi\CollectionModify::arrayAppend(string $collection_field, string $expression_or_literal): mysql_xdevapi\CollectionModify

필드의 여러 요소가 배열로 표시되므로 문서의 필드에 요소를 추가합니다. arrayInsert()와 달리 arrayAppend()는 항상 배열 끝에 새 요소를 추가하지만 arrayInsert()는 위치를 정의할 수 있습니다.


매개변수

collection_field
새 요소가 삽입되는 필드의 식별자입니다.
expression_or_literal
문서 필드 배열의 끝에 삽입할 새 요소입니다.

반환 값

명령을 실행하거나 추가 작업을 추가하는 데 사용할 수 있는 CollectionModify 개체입니다.


Examples

예제 #1 mysql_xdevapi\CollectionModify::arrayAppend() 예제

                  
<?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":   "Bernie",
    "traits": ["Friend", "Brother", "Human"]}')
  ->execute();

$collection
  ->modify("name in ('Bernie', 'Jane')")
  ->arrayAppend('traits', 'Happy')
  ->execute();

$result = $collection
  ->find()
  ->execute();

print_r($result->fetchAll());
?>
                  
                

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

Array
(
    [0] => Array
        (
            [_id] => 00005b6b5361000000000000010c
            [name] => Bernie
            [traits] => Array
                (
                    [0] => Friend
                    [1] => Brother
                    [2] => Human
                    [3] => Happy
                )
        )
)