NoSQL Zone is brought to you in partnership with:

Daniel Mohl is a professional software engineer/architect whose interests include understanding the intricacies of various programming languages, enterprise application architecture, and how to bridge the gap between business and technology. He works with F#, C#, CoffeeScript, JavaScript, Erlang, ASP.NET MVC, WPF, WCF, Silverlight, WP7, SQL Server, etc. He is a F# MVP, C# Insider, F# Insider, blogger, speaker, and event organizer. You can follow him on twitter at www.twitter.com/dmohl. Daniel is a DZone MVB and is not an employee of DZone and has posted 30 posts at DZone. You can read more from them at their website. View Full User Profile

NoSQL Helper Libraries: FSharpCouch and MongoFS

07.09.2012
| 2275 views |
  • submit to reddit

I've been working on a few new libraries lately that focus on providing functional wrappers around various NoSQL options.

FSharpCouch:

FSharpCouch is something that I wrote about a little over two years ago. At the time, it was more of an educational exercise, but I have since revised it and found aspects of it to be useful. This is now available on NuGet as package ID FSharpCouch.

Here's an example:

type Person = {
    FirstName : string
    LastName : string
}

let couchUrl = "http://localhost:5984"
let databaseName = "people"

let result = { FirstName = "John"; LastName = "Doe" }
             |> createDocument couchUrl databaseName

let createdPerson = getDocument<Person> couchUrl databaseName result.id


You can find additional examples and the full source at https://github.com/dmohl/FSharpCouch.

MongoFs:

MongoFs currently has a primary focus on function composition as it relates to setting up the MongoDB client aspects of server, database, and collection. It simply wraps functions around the necessary methods of the C# Mongo Driver and auto opens the encompassing module.

Here's an example:

let dbName = "SomeName"
let collectionName = "SomeName"

type Person = {
    mutable _id : ObjectId
    mutable FirstName : string
    mutable LastName : string
}

createLocalMongoServer()
|> getMongoDatabase dbName
|> getMongoCollection<Person> collectionName

{ _id = ObjectId.GenerateNewId(); FirstName = "John"; LastName = "Doe" }
|> people.Insert |> ignore

let person = people.FindOne()


You can get it from NuGet as package ID MongoFs and find more examples and source at https://github.com/dmohl/MongoFs.
 

Published at DZone with permission of Daniel Mohl, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)