Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Doing a recursive unset of _id fields in the DB exporter, as MongoDB #769

wants to merge 1 commit into from

3 participants


doesn't let you use $set and modify _id. So if you have a document that has a sub-object and that object also has a _id field, the existing implementation breaks because it only considers the top-level _id key. This patch recursively traverses the data and removes all _id key references during an update.


I must not be understanding the problem correctly, because MongoDB definitely does let you update _id fields inside of sub-objects, which this patch would appear to break.

Maybe attaching a unit test (which is required for all patches anyway) would clear things up. /cc @gwoo


Just did this from the console:

>{ bar: { _id: new ObjectId() }})
> db.foos.update({}, { $set: { bar: { _id: new ObjectId() }}})

Works fine.

Are we talking about two different things here?


Hi @coogle, any news on this ?


Closing this for now. Please re-open when we have a test or something to demonstrate the issue.

@nateabele nateabele closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 26, 2012
  1. @coogle

    Doing a recursive unset of _id fields in the DB exporter, as MongoDB

    coogle authored
    doesn't let you use $set and modify _id
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 1 deletion.
  1. +14 −1 data/source/mongo_db/Exporter.php
15 data/source/mongo_db/Exporter.php
@@ -46,7 +46,20 @@ public static function toCommand($changes) {
$result[$to] = $changes[$from];
- unset($result['$set']['_id']);
+ $unsetKeyRecursive = function(&$array, $key = "_id") use (&$unsetKeyRecursive)
+ {
+ unset($array[$key]);
+ foreach($array as &$value) {
+ if(is_array($value)) {
+ $unsetKeyRecursive($value, $key);
+ }
+ }
+ };
+ $unsetKeyRecursive($result['$set']);
return $result;
Something went wrong with that request. Please try again.