GithubHelp home page GithubHelp logo

rmunn / mongodb.fsharp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tkellogg/mongodb.fsharp

0.0 1.0 1.0 326 KB

Silent utilities to make the official MongoDB driver feel natural to work with in F#

Home Page: http://nuget.org/packages/MongoDB.FSharp/

License: Other

F# 96.59% Dockerfile 0.75% Batchfile 0.80% Shell 1.86%

mongodb.fsharp's Introduction

This project takes the official .NET MongoDB driver and fixes the warts that make it hard to work with in F#. By default, F# loves immutable types but the MongoDB driver can't handle them out of the box. F# collections like list, map and seq aren't properly

Installation

Note also that this requires at least version 1.8.1 of the official MongoDB driver. That version includes some API that makes this whole project possible.

Install NuGet and run this from the Package Manager Console.

PM> Install-Package MongoDB.FSharp

To use the C# driver just type

open MongoDB.Bson
open MongoDB.Driver

Somewhere during startup you have to register MongoDB.FSharp. It's basically a one-liner that looks like:

open MongoDB.FSharp
Serializers.Register()

The Serializers.Register() call just registers serializers with the MongoDB driver.

Usage

Use MongoDB.FSharp like you normally would in C#.

type Person = { Id : BsonObjectId; Name : string; Scores : int list }

let connectionString = "mongodb://localhost"
let client = new MongoClient(connectionString)
let db = client.GetDatabase("test")

let collection = db.GetCollection<Person> "people"

let id = BsonObjectId(ObjectId.GenerateNewId())
do! insertOne collection { Id = id; Name = "George"; Scores = [13; 52; 6] }

let! george = findOneById collection id

The example above would work naturally in C#, but remember that record types like Person are immutable! With MongoDB.FSharp, this just works.

What's Implemented

Serializing and Deserializing these items should work great:

  • list
  • Options
  • Discriminated unions
  • Records

Road Map

  • Better support for Linq and quotations
  • A functional API for simpler access
  • Better testing so you can be confident putting this in production

mongodb.fsharp's People

Contributors

carsten-j avatar fristi avatar rmunn avatar tkellogg avatar

Watchers

 avatar

Forkers

fcolavecchia

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.