I have described how to work with MongoDB in Sitecore in this answer.
Querying
Applying it for your case, the code will be similar to this:
MongoDbDriver driver = MongoDbDriver.FromConnectionString("analytics");
MongoDbCollection collection = driver["FormData"];
Guid formId = new Guid("insert-some-guid-here");
MongoCursor<FormData> cursor =
collection.FindAs<FormData>(
Query<FormData>.EQ(_ => _.FormID, formId));
IList<FormData> results = cursor.ToList();
Note that I'm using a System.Guid
object to define the form ID. You should not use binary IDs in C# code.
Data mapping
The C# driver can automatically map data to strongly-typed models. I assume that the collection you're using in your question contains WFFM data. If that is the case, all you'll need to do is use WFFM's data class FormData
. It's already registered in the driver, so just reference Sitecore.WFFM.Abstractions.dll
in your project and add the following directive in the beginning of your C# file:
using Sitecore.WFFM.Abstractions.Analytics;