On Sunday, 15 July 2012 at 19:36:50 UTC, Sönke Ludwig wrote:

According to the BSON spec Undefined is deprecated. For that
reason Type.Null is returned instead, so bson.isNull() or
bson.type == Bson.Type.Null should work.

Alternatively you can also use bson.myfield.opt!int(-1) != -1
to test for an integer field "myfield" and get its value at the
same time.

Looks like isNull() isn't working, at least not from my diet
page. In the data it is processing the first three entries
contain the field but the fourth does not which generates the
error.

  • auto endVerseBson = bsonDoc["endVerse"];
  • if(!endVerseBson.isNull())
  • {
  • import std.stdio;
  • writeln("Type for endVerse is ", endVerseBson.type);
  • float endVerse;
  • deserializeBson!float(endVerse, endVerseBson);
  • formattedWrite(referenceAppender, "-%0g", endVerse);
  • }

When run yields:

Type for endVerse is Double
Type for endVerse is Double
Type for endVerse is Double
Type for endVerse is Null
[7F17E05F6017:7F17E05F4317 ERR] Error after page has been
written: BSON value is type 'Null', expected to be one of [Double]

So, the isNull passes but the type is actuall Null.

Replacing the if test with this also doesn't work:

  • if(endVerseBson.type != Bson.Type.Null)

When run it yields:

Type for endVerse is Double
Type for endVerse is Double
Type for endVerse is Double
Type for endVerse is Null
[7F0B1E12D00B:7F0B1E12B30B ERR] Error after page has been
written: BSON value is type 'Null', expected to be one of [Double]