(mongodb >=1.2.0)
MongoDB\Driver\WriteConcern::bsonSerialize — 傳回一個物件以進行 BSON 序列化
此函式沒有參數。
傳回一個物件,用於將 WriteConcern 序列化為 BSON。
範例 #1 使用多數寫入關注的 MongoDB\Driver\WriteConcern::bsonSerialize()
<?php
$wc = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY);
var_dump($wc->bsonSerialize());
echo "\n", MongoDB\BSON\Document::fromPHP($wc)->toRelaxedExtendedJSON();
?>
上述範例將輸出類似以下的內容:
object(stdClass)#2 (1) { ["w"]=> string(8) "majority" } { "w" : "majority" }
範例 #2 使用 wtimeout 和 journal 的 MongoDB\Driver\WriteConcern::bsonSerialize()
<?php
$wc = new MongoDB\Driver\WriteConcern(2, 1000, true);
var_dump($wc->bsonSerialize());
echo "\n", MongoDB\BSON\Document::fromPHP($wc)->toRelaxedExtendedJSON();
?>
上述範例將輸出類似以下的內容:
object(stdClass)#2 (3) { ["w"]=> int(2) ["j"]=> bool(true) ["wtimeout"]=> int(1000) } { "w" : 2, "j" : true, "wtimeout" : 1000 }