I would like to create types in D and then populate the types easily without too much specific DB code.

I have tried

deserializeBson!MyType(t);

which seems to work but I end up with errors that are not good and I'd rather have it all self contained. e.g., I could add a query interface that mixins in with such types that can be used to create types. e.g.,

auto t = MyType.Query(["name":"test"]);

That should be easy enough and probably adaptable to other databases easily(just change Query).

The main problem I'm having is that I get errors like

Missing non-optional field 'id' of type 'MyType'.

If I add id to the document it works fine. I have an ID field and mongo's _id already so I'm not sure why deserializeBson is requiring an id field.

Also, is deserialization the way to go here? is there anything faster/better? Ultimately I'd like to avoid interacting with the database as much as possible and do everything as if working in D directly(simply with an "offline" memory store).