Created
November 29, 2020 23:13
-
-
Save naartjie/a6a1f369d98a7c101f7643e6c70a439a to your computer and use it in GitHub Desktop.
Revisions
-
naartjie created this gist
Nov 29, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ 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 This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ ```sh dotnet new console -lang F# -o MyMongoApp dotnet add package MongoDB.Driver --version 2.11.4 ```