On Sun, 12 Mar 2017 23:09:53 GMT, Carl Sturtivant wrote:

auto cursor = db[collectionname].find();
foreach( rec; cursor) {
    s = rec[fieldname].to!string;
    // rec[fieldname] is a Bson string
}

Here s is assigned quoted text looking like a string literal if printed, i.e. as if Bson is being converted to Json text, suitable for display in the console or a log.

However, what if we want to get the string, not its representation as a string literal?

We can do this if we use a struct to represent each of the results of find, but this is not possible if the structure of the collection is not known at compile time. So how do we proceed in this dynamic case?

I don't use bson, but according to http://vibed.org/api/vibe.data.bson/ it's rec[fieldname].get!string - the same as with json.