mysql_xdevapi\Collection
PHP Manual

Collection::replaceOne

(No version information available, might only be in Git)

Collection::replaceOneReplace one collection document

说明

public mysql_xdevapi\Result mysql_xdevapi\Collection::replaceOne ( string $id , string $doc )

Updates (or replaces) the document identified by ID, if it exists.

参数

id

ID of the document to replace or update.

doc

Collection document to update or replace the document matching the id parameter.

This document can be either a document object or a valid JSON string describing the new document.

返回值

A Result object that can be used to query the number of affected items and the number warnings generated by the operation.

范例

Example #1 mysql_xdevapi\Collection::replaceOne() example

<?php
// Assuming $coll is a valid Collection object

// Replace the document with the ID:00005ad66abf0001000400000003 with the provided new document
$coll->replaceOne('00005ad66abf0001000400000003''{"name": "Filip", "age": 20, "job": "Programmatore"}');

// In this example I'm extracting the document with ID 16, the after some modifications
// I'm replacing that document with the modified one.
$doc $coll->getOne(16);
$doc["age"] = "55";
$doc["job"] = "SeniorProgrammatore";
$coll->replaceOne(16$doc);

?>

mysql_xdevapi\Collection
PHP Manual