Collection::replaceOne

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

Collection::replaceOneReplace one collection document

Beschreibung

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

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

Parameter-Liste

id

ID of the document to replace or update. Typically this is the _id that was generated by MySQL Server when the record was added.

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.

Rückgabewerte

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

Beispiele

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

<?php
$session 
mysql_xdevapi\getSession("mysqlx://user:password@localhost");

$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();

$schema     $session->getSchema("addressbook");
$collection $schema->createCollection("people");

$result $collection->add('{"name": "Alfred", "age": 18, "job": "Butler"}')->execute();

// Normally the _id is known by other means, 
// but for this example let's fetch the generated id and use it
$ids       $result->getGeneratedIds();
$alfred_id $ids[0];

// ...

$alfred $collection->getOne($alfred_id);
$alfred['age'] = 81;
$alfred['job'] = 'Guru';

$collection->replaceOne($alfred_id$alfred);

?>

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Was genau bedeutet "Vibe Coding"? Ein tiefgehender Blick für Entwickler

In der Welt der Softwareentwicklung gibt es unzählige Wege, wie man an ein Projekt herangeht. Manche schwören auf strikte Planung, andere auf bewährte Algorithmen und wieder andere lassen sich von etwas ganz anderem leiten: ihrem Gefühl. ...

admin

Autor : admin
Kategorie: Software & Web-Development

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

U4GM - Pokémon Legends: Z-A Best Mega Forms for Each Type

In Pokémon Legends: Z-A, Mega Evolutions provide a unique way to enhance your Pokémon's power and versatility. These transformations not only bo ...

Geschrieben von SamuelSullivan188 am 16.10.2025 10:57:32
Forum: PHP Developer Forum
Fatal Error bei übergabe an Datenbank 1 Formular funktioniert das andere nicht

Also ich bin grad bisl am verzweifel ich habe 2 Formulare mit php übergabe in die Datenbank. Ein Formular funktioniert super, dass zweite gibt ne ...

Geschrieben von phppower am 15.10.2025 21:03:17
Forum: PHP Developer Forum
Laravel Datenbankabfrage

Wenn Sie Ihre Events aus der Datenbank holen, sollten Sie gleich den zugehörigen Benutzer mitladen (sog. Eager Loading).​ Among Us Free (https: ...

Geschrieben von chrisy38 am 15.10.2025 15:12:49
Forum: PHP Developer Forum
Laravel Datenbankabfrage

Habe die Lösung selber gefunden. Scheint so als wäre auch das Forum gestorben. Statt $events = DB::table('events') Lese ich es mit $events ...

Geschrieben von BrainAFK am 14.10.2025 21:13:21
Forum: PHP Developer Forum