Mondocks 0.1.0-beta2
See the version list below for details.
dotnet add package Mondocks --version 0.1.0-beta2
NuGet\Install-Package Mondocks -Version 0.1.0-beta2
<PackageReference Include="Mondocks" Version="0.1.0-beta2" />
paket add Mondocks --version 0.1.0-beta2
#r "nuget: Mondocks, 0.1.0-beta2"
// Install Mondocks as a Cake Addin #addin nuget:?package=Mondocks&version=0.1.0-beta2&prerelease // Install Mondocks as a Cake Tool #tool nuget:?package=Mondocks&version=0.1.0-beta2&prerelease
Mondocks
A CE library to ease your work with mongodb from F#
This library is based on the mongodb manual reference https://docs.mongodb.com/manual/reference/command/
the mongodb .NET driver is made entirely for C# and it expects you to pass data and information in a way C# can (reflection, inheritance among others) so I tried to go in a different way providing a kind of DSL that allow you to create json files leveraging the dynamism of anonymous records since they behave almost like javascript objects.
Writing commands should be almost painless these commands produce a JSON string that can be utilized directly on your application or even copy/pasted into the mongo shell
Commands are kind of a version of raw sql queries
but they allow you to do what you already know how to do without much changes to the objects you might be manipulating already
Sample Usage
Check out this quick sample of the work so far
open System
open MongoDB.Driver
open MongoDB.Bson
open Mondocks.Queries
open Mondocks.Types
let createUsers minAge maxAge =
let random = Random()
insert "users" {
documents
[
{| name = "Peter"; age = random.Next(minAge, maxAge); |}
{| name = "Sandra"; age = random.Next(minAge, maxAge); |}
{| name = "Mike"; age = random.Next(minAge, maxAge); |}
{| name = "Perla"; age = random.Next(minAge, maxAge); |}
{| name = "Updateme"; age = 1; |}
{| name = "Deleteme"; age = 50; |}
]
}
let updateUser (name: string) (newName: string) =
update "users" {
updates
[
{ q = {| name = name |}
u = {| name = newName; age = 5 |}
multi = Some false
upsert = Some false
collation = None
arrayFilters = None
hint = None }
]
}
let deleteUser (name: string) =
delete "users" {
deletes [
{ q = {| name = name |}
limit = 1
collation = None
hint = None
comment = None }
]
}
// Define a function to construct a message to print
let getUsersOverAge (age: int) =
find "users" {
filter {| age = {| ``$gt``= age |} |}
limit 2
skip 1
}
type User = { _id: ObjectId; name: string; age: int }
[<EntryPoint>]
let main argv =
let client = MongoClient("mongodb://localhost:27017")
let db = client.GetDatabase("mondocks")
let userscmd = createUsers 15 50
let result = db.RunCommand<InsertResult>(JsonCommand userscmd)
printfn $"InsertResult: %A{result}"
let over20 = getUsersOverAge 20
let result = db.RunCommand<FindResult<User>>(JsonCommand over20)
printfn $"FindResult Ok: %d{result.ok}"
result.cursor.firstBatch |> Seq.iter (fun value -> printfn $"%A{value}")
let updatecmd = updateUser "Updateme" "Updated"
let result = db.RunCommand<UpdateResult>(JsonCommand updatecmd)
printfn $"UpdateResult: %A{result}"
let deletecmd = deleteUser "Deleteme"
let result = db.RunCommand<DeleteResult>(JsonCommand deletecmd)
printfn $"DeleteResult: %A{result}"
0 // return an integer exit code// return an integer exit code
Thanks for the early feedback in twitter from Isaac, Zaid, Alexey, Alexander, and the F# community you can follow it on the first issue
WIP
This is a work in progress, you can help providing feedback about it's usage
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- FSharp.Core (>= 5.0.0)
- FSharp.SystemTextJson (>= 0.15.14)
- MongoDB.Bson (>= 2.11.4)
-
net5.0
- FSharp.Core (>= 5.0.0)
- FSharp.SystemTextJson (>= 0.15.14)
- MongoDB.Bson (>= 2.11.4)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Mondocks:
Package | Downloads |
---|---|
Mondocks.Net
Package Description |
|
Mondocks.Fable
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.6.0 | 289 | 9/26/2023 |
0.5.0 | 773 | 11/28/2022 |
0.4.8 | 1,054 | 2/14/2022 |
0.4.2 | 650 | 7/27/2021 |
0.3.18 | 435 | 12/23/2020 |
0.3.15 | 392 | 12/17/2020 |
0.2.0 | 403 | 12/7/2020 |
0.1.0 | 439 | 11/27/2020 |
0.1.0-beta3 | 280 | 11/23/2020 |
0.1.0-beta2 | 328 | 11/23/2020 |
0.1.0-beta1 | 271 | 11/22/2020 |