Werbung
MongoCollection::save
(PECL mongo >=0.9.0)
MongoCollection::save — Saves an object to this collection
Beschreibung
public boolean MongoCollection::save
( array $a
)
If the object is from the database, update the existing database object, otherwise insert this object.
Parameter-Liste
- a
-
Array to save.
Rückgabewerte
Returns if the object was saved.
Beispiele
PHP Code
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
$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);