doctrine/mongodb — Issue #31: GridFS::doUpdate throws error when non-dirty file metadata is updated
Author: housebolt
Created: 2011-11-14 23:36:43+00:00
State: open

If a non-dirty GridFS file has some metadata fields updated with an $unset command, GridFS:doUpdate throws "Invalid modifier specified: $set"

Below is merely an example of what's happening, not code I'm actually using:

```php
$query = array('_id' => new \MongoID('4e2b16689fd265b601000001'));

$file = new \Doctrine\MongoDB\GridFSFile();
$file->isDirty(false);

$newObj = array('$set' => array('file' => $file), array('$unset' => array('specialmetafield' => true));

\Doctrine\MongoDb\GridFs::doUpdate($query, $newObj);
```

Throws a MongoCursorException with message "Invalid modifier specified: $set", and it looks like it's passing an empty $set modifier to MongoCollection::update().

This query is from the Doctrine ODM w/Symfony2, it's how it updates GridFS files if a particular field has been emptied but the actual file has not been updated.

The fix is simple, just make sure that if $newObj has a key of '$set' and it's an empty array, it should be unset.