如果我在集合中用自身替换文档,则文档似乎已更改。由于这个问题,我的数据变得无法使用。我究竟做错了什么?
<?php
$login = '***removed***';
$pass = '***removed***';
$schema_name = 'dev';
$collection_name = 'test';
$session = mysql_xdevapi\getSession("mysqlx://$login:$pass@localhost");
$schema = $session->getSchema($schema_name);
$collection = $schema->getCollection($collection_name);
// Delete all documents in the collection.
$collection->remove('true')->execute();
// Add one document and get its ID.
$result = $collection->add('{ "accent": "\u00e8" }')->execute();
$ids = $result->getGeneratedIds();
$doc_id = $ids[0];
// Read the document from the database.
$row = $collection->getOne($doc_id);
print "1st getOne() : " . $row['accent'] . "\n";
// Replace the document with itself.
$collection->replaceOne($doc_id, $row);
// Read the document from the database again.
$row = $collection->getOne($doc_id);
print "2nd getOne() : " . $row['accent'] . "\n";
// One more time.
$collection->replaceOne($doc_id, $row);
$row = $collection->getOne($doc_id);
print "3rd getOne() : " . $row['accent'] . "\n";
?>
上述脚本的输出:
$ php test.php
1st getOne() : è
2nd getOne() : \u00e8
3rd getOne() : \\u00e8
我正在使用 PHP v7.3.19 和 mysql_xdevapi v8.0.22。