(沒有版本資訊,可能只在 Git 中)
CollectionFind::fields — 設定文件欄位篩選器
定義查詢要返回的欄位。如果未定義,則使用所有欄位。
projection
可以是單個字串或字串陣列,用於識別要為每個符合搜尋條件的文件返回的欄位。
一個 CollectionFind 物件,可用於進一步處理。
範例 #1 mysql_xdevapi\CollectionFind::fields() 範例
<?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");
$create = $schema->createCollection("people");
$create
->add('{"name": "Alfred", "age": 18, "job": "Butler"}')
->execute();
// ...
$collection = $schema->getCollection("people");
$result = $collection
->find('job like :job and age > :age')
->bind(['job' => 'Butler', 'age' => 16])
->fields('name')
->execute();
var_dump($result->fetchAll());
?>
上述範例將輸出類似以下的內容
array(1) { [0]=> array(1) { ["name"]=> string(6) "Alfred" } }