doctrine/mongodb-odm — pull request #235 by jwage (2012-01-20 06:00:22+00:00)
Title: #218 Add object upsert functionality.

With this the following will work:

$user = new User();
$user->setId('4f163fbaf05a2f6019000072');
$user->setUsername('jwage');
$dm->persist($user);
$dm->flush();

The above would result in the following query:

$userCollection->update(
array('_id' => new MongoId('4f163fbaf05a2f6019000072')),
array(
'$set' => array('username' => 'jwage')
),
array('upsert' => true)
);