On Sun, 04 May 2014 16:31:26 GMT, Jack Applegame wrote:

How to distinguish a non-existent field from a null field in Bson document retrieved from Mongo?

if(bson["field"].isNull) {
    // non-existent field or null field???
}

Currently the only way is to foreach over all elements and see if the field in question is encountered. I sometimes wish that I had used Bson.undefined instead of Bson.null_ to denote non-existent fields, but the standard says that it's deprecated. Changing the value now could silently break existing code, so that's not really an option. It would be possible to add a bool hasItem(string) method, but it would also have to use the inefficient foreach way.

What I'm planning to do in the long run is to let both, Json and Bson just be aliases for a standard algebraic variant type, just with different supported sub types. BSON will then not be represented as raw BSON in memory anymore (which consequently will be less efficient for reading a BSON document as Bson), but deserializeBson will be extended to directly parse an input range of bytes instead of a Bson value, so that there is no efficiency loss when working with static types.