Created
January 29, 2010 06:39
-
-
Save mattpodwysocki/289501 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Microsoft.FSharp.Linq | |
open Microsoft.FSharp.Linq.Query | |
open MongoDB.Driver | |
open MongoDB.Linq | |
let inline (?) this key = | |
( ^a : (member get_Item : ^b -> ^c) (this,key)) | |
let inline (?<-) this key value = | |
( ^a : (member set_Item : ^b * ^c -> ^d) (this,key,value)) | |
let mongo = new Mongo() | |
mongo.Connect() |> ignore | |
let books = mongo?BookReviews?Books | |
// Insert books | |
let book1 = new Document() | |
book1?Title <- "Programming F#" | |
book1?Author <- "Chris Smith" | |
book1?Publisher <- "O'Reilly" | |
book1?Rating <- box 5.0 | |
let book2 = new Document() | |
book2?Title <- "Real World Haskell" | |
book2?Author <- "O'Sullivan, Gorezen, Stewart" | |
book2?Publisher <- "O'Reilly" | |
book2?Rating <- box 4.6 | |
let book3 = new Document() | |
book3?Title <- "Real World Functional Programming: With Examples in F# and C# " | |
book3?Author <- "Petricek, Skeet" | |
book3?Publisher <- "Manning" | |
book3?Rating <- box 4.2 | |
books.Insert(book1) | |
books.Insert(book2) | |
books.Insert(book3) | |
let queryableBooks = MongoLinqEx.AsQueryable(books) | |
let oReillyBooks = | |
query <@ seq { for book in queryableBooks do | |
if book?Publisher = box "O'Reilly" then | |
yield book } @> | |
let firstBook = | |
query <@ seq { for book in queryableBooks do | |
if book?Title = box "Programming F#" then | |
yield book } @> | |
|> Seq.head | |
mongo.Disconnect() |> ignore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment