Using DocumentDB With F#

DocumentDB is Microsoft’s non-sql offering on Azure. I have limited experience with non-sql databases in general so I thought it would be a good way to try out no-sql on a real project using F#. The first thing I noticed is that you can’t get to DocumentDB from the “old” azure portal –> you have to spin it up in the new one:

Once I created my DocumentDB instance, I went to the getting started guide and found the code samples to accomplish the basic tasks you would expect to see in any database product. The getting started guide does not make it an explicit step, but you need to spin up a new FSharp project in Visual Studio and then use NuGet to get the latest SDK.

Once the NuGet package is installed, I went to a script to add the references:

Interestingly, that new database does not show up in the Azure portal until you do a post back

which really surprised me –> I figured the new portal would use SignalR. In any event, with the database created, I went to create a collection, which seems roughly analogous to a table in a RDBMS world:

In any event, one thing profoundly vexed me: “if I don’t have a document link to an existing database, how do I get documents out of the database?” I started Googling around a bit and found this helpful post on Stack Overflow.

It is makes some sense then to use queries to traverse data base and collections by using queries –> esp because they are using linq. I fired up a new script, put the stack overflow code in,

I then went back to stack overflow to see if there was a more idiomatic way to interact with the documents and Panagiotis Kanavos was kind of enough to answer my question here. Of the different possibilities offered, I settled on this style: