mysql_xdevapi\Collection
PHP Manual

Collection::addOrReplaceOne

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

Collection::addOrReplaceOneAdd or replace collection document

说明

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

Add a new document, or replace a document if it already exists.

Here are several scenarios for this method:

参数

id

This is the filter id. If this id or any other field that has a unique index already exists in the collection, then it will update the matching document instead.

doc

This is the document to add or replace, which is a JSON string.

返回值

A Result object.

范例

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

<?php
/*
    Assuming that $coll is a valid collection object, the following call to addOrReplaceOne
    will search for a document with the ID 121 and will either replace it or add a new one with
    that ID.
*/
$res $coll->addOrReplaceOne('121''{"name": "Sakila", "age": 30, "job": "Radio", "_id": "121" }');

?>

mysql_xdevapi\Collection
PHP Manual