poiati/gmongo — Issue #7: Write _id to map on save()
Author: paulicka
Created: 2011-10-16 23:21:37+00:00
State: open

def x = [monkey: 23]
db.collection.save(x)
assertNotNull x._id

This will fail.
The reason, I assume, is because under the hood, you create a BasicDBObject under the hood from the Map,
then call save() using that BasicDBObject.

The problem is that the _id is lost.
I fixed it in my code by explicitly creating a BasicDBObject.

def x = new BasicDBObject(monkey: 23)
db.collection.save(x)
assertNotNull x._id

And that's fine.
It's just wierd, because it is different from the mongosh behavior for save() on a JSON object.