mongodb 1.4.0-rc9 has a `binId` field of type Buffer on ObjectIDs, which
caused Meteor to crash when retrieving a document that was made up of
just an EJSON user-defined type. (Which should not necessarily be
supported, but `replaceNames` should probably treat Buffers as Arrays
Follow-up to 63b3119; further addresses #2095.
There were a few problems here:
- We didn't check that the argument to insert was a document. (EJSON
custom types don't count as documents, because they don't have _ids!)
- The check to see if something coming from the database was an EJSON
custom type didn't match the check in ejson.js (specifically, it was
missing size===2). This made it sort of look like you could use EJSON
custom types as top-level documents, until a change in the MongoDB
driver made made that coincidental almost-working code stop working.
- The replaceNames function wasn't documented as only taking pure JSON,
so it wasn't obvious that "it throws when there's a Buffer" was a bug
in the caller rather than a bug in replaceNames.
This should all be resolved now. Use cases like CollectionFS which were
mislead by these bugs into believing that an EJSON custom type could be
a document should move their custom type into a field.