Mongo

A lot of changes have been coming to the MongoDB PHP driver. If you are upgrading from 1.2.x, you should take a second look at your insert syntax to be sure it won’t break. There are a couple of other things though but except you are using MongoDB on a big production scale, you may not need to worry. (We use MongoDB on Prowork for the notification logs and activity stream).

That said, from version 1.3, you can’t pass a boolean option to signify a safe insert. This will fail:

$r = $this->mongodb->notifications->activities->insert($query, true);

Use writeConcern instead

$r = $this->mongodb->notifications->activities->insert($query, array("w" => 1));

Just by the way, the other things

  1. Connection and Persistence [1.2.0]

    Connection to the DB is now persistent by default

    try {
      // This
      $mongodb = new Mongo();
      // is same as this
      //$mongodb = new Mongo("localhost:27017", array("persist" => "x"));
    }
    catch (MongoConnectionException $e) {
      // log error ($e)
    }
    
  2. Updates and upserts (insert if not exist) [1.3.0]

    One cool thing about update is allowing you insert the data if it doesn’t exist in the collection (table). You have to specify that in an array option and not as a boolean in v1.3.0 and up.

    // Wrong
    $mongodb->db->collection->update($criteria, $data, true);
    // Right
    $mongodb->db->collection->update($criteria, $data, array('upsert' => true));
    
  3. Deletes. “JustOne” please [1.3.0]

    Remove use to allow a boolean option to specify you want to delete just one record. Now you have to speifiy it as an array parameter.

    // Wrong
    $mongodb->db->collection->remove($criteria, true);
    // Right
    $mongodb->db->collection->remove($criteria, array('justOne' => true));
    

There are even more others you may want to take a look at: MongoDB PHP Driver 1.3.0 Changelog