MongoCollection::remove
MongoCollection::__toString
MongoCollection
PHP Manual

# MongoCollection::save

(PECL mongo >=0.9.0)

MongoCollection::save — Saves an object to this collection

### Opis

public mixed MongoCollection::save ( array `$a` [, array `$options` = array() ] )

If the object is from the database, update the existing database object, otherwise insert this object.

### Parametry

`a`

  Array to save.

`options`

  Options for the save.

  - "safe"

    Check that the save succeeded.

### Zwracane wartości

Returns if the object was saved.

### Błędy/Wyjątki

Throws MongoCursorException if the "safe" option is set and the save fails.

### Rejestr zmian

Wersja | Opis
--- | ---
1.0.5 | Added "options" parameter.

### Przykłady

Przykład #1 MongoCollection::save() example

`<?php
$obj = array('x' => 1);
// insert $obj into the db
$collection->save($obj);
// add another field
$obj['foo'] = 'bar';
// $obj cannot be inserted again, causes duplicate _id error
$collection->insert($obj);
// save updates $obj with the new field
$collection->save($obj);
?>`

MongoCollection::remove
MongoCollection::__toString
MongoCollection
PHP Manual