Using a cut down viewmodel to just return some of the data:

Which makes sense, it takes a while to take a document from the server, convert to a .net object with type-checking etc and then serve that up.

It seems that the time difference between returning a model and a BSON document is on-par, it’s the conversion from RAW data to the BSON representation in .net is taking the time.

I’ve not delved into the dotnet driver but the use cases seem to be if you want raw performance to plough through the data as fast as possible, get them as raw BSON objects and deal with that, if you are going to process them and pass to a strongly typed model in your app, then take the overhead of the conversion but just do this when you’re not pulling a million records from the server.

Checking about a bit I found this:
https://jira.mongodb.org/browse/CSHARP-666

Which seems to allow to get the document as raw and then just deserialise the elements you needs as used, as opposed to on the whole document. This could be a halfway approach, grab the data as fast as you can and then process as and when, at which point you take the overhead. Note the details in that CR for how it de-serialises nested documents.

/Edit I create a pull request so you can see what I did to generate the above, I was trying to use generics to pass in different view models but I kept failing at syntax and didn’t have the time to work through it:

Apologies for anyone who finds the code layout offensive :slight_smile: