Einfügen:
$mongo = new MongoClient();
$db = $mongo->mydb1;
$data = array(
'emp_id' => '1',
'first_name' => 'Tiger',
'last_name' => 'Nixon'
);
$collection = $db->createCollection("emp_details");
if ($collection->insert($data)) {
echo 'Record inserted successfully';
}Aktualisieren:
$newdata = array(
'$set' => array("age" => "55", "salary" => "320000")
);
$condition = array("emp_id" => "1");
if ($collection->update($condition, $newdata)) {
echo 'Record updated successfully';
}Hinweis: Die alte MongoClient-API ist veraltet. Für neue Projekte sollte der aktuelle MongoDB-Treiber mit insertOne und updateOne verwendet werden.