fakemongo/fongo — pull request #9 by mathieubodin (2014-02-19 16:05:23+00:00)
Title: Ensure DBRef have DB set.

As I was working with nosqlunit, I noticed an odd use case: I insert data from a JSON file into an in memory Fongo. JSON file was having some DBRefs definitions without $db set and as you might guess Fongo was retrieving those DBRefs without it. Any attempt of fetch on such DBRefs ends with an error, indeed db is null !

The main issue is that the Java driver for mongoDB doesn't care of the $db parameter when parsing JSON, as it is stated as optional (see http://docs.mongodb.org/manual/reference/database-references/). So I proposed a patch to nosqlunit in order to insert "proper" data into Fongo.

Nevertheless, It seems that the real MongoDB ensures DBRefs are provided with this $db parameter. So here is a proposition of patch allowing FongoDBCollection to ensure DBRefs are usable as MongoDB does.