函数:MongoDB\Driver\Session::isDirty()
适用版本:MongoDB 1.4.0及以上版本
用法:该函数用于检查会话对象是否已被修改。
示例:
// 创建MongoDB会话
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$session = $manager->startSession();
// 设置会话选项
$session->startTransaction();
$session->setOptions([
'readConcern' => new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::LOCAL),
'writeConcern' => new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY),
'readPreference' => new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY),
]);
// 检查会话是否已被修改
$isDirty = $session->isDirty();
if ($isDirty) {
echo "会话已被修改";
} else {
echo "会话未被修改";
}
// 结束会话
$session->endSession();
注意事项:
isDirty()函数来检查会话是否已被修改。endSession()函数来结束会话,释放相关资源。