dotnet new console -lang F# -o MyMongoApp
dotnet add package MongoDB.Driver --version 2.11.4
Created
November 29, 2020 23:13
-
-
Save naartjie/a6a1f369d98a7c101f7643e6c70a439a to your computer and use it in GitHub Desktop.
F# MongoDB Starter
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 MongoDB.Driver | |
open MongoDB.Bson | |
open MongoDB.Driver.Linq | |
let doMongoStuff () = | |
let client = MongoClient("mongodb://localhost:27017") | |
let db = client.GetDatabase("rebujito-test") | |
let collectionName = "users" | |
let collection = db.GetCollection<BsonDocument>(collectionName) | |
let count = collection.CountDocuments(FilterDefinitionBuilder().Empty); | |
printfn "we've got %d elements in %s" count collectionName | |
async { | |
printfn "starting async workflow..." | |
let! count = collection.AsQueryable<BsonDocument>().CountAsync() |> Async.AwaitTask | |
printfn "we've got %d elements in %s" count collectionName | |
let! users = collection.AsQueryable<BsonDocument>().Where(fun x -> true).Select(fun x -> x).ToListAsync() |> Async.AwaitTask | |
printfn "we got %d users" users.Count | |
} |> Async.RunSynchronously | |
[<EntryPoint>] | |
let main _argv = | |
printfn "Hello Mongo" | |
doMongoStuff () | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment