F# wrapper over MongoDB.Driver.
let collection = "bagno"
let database = "bagnoDBTests"
let config = {
host = "0.0.0.0"
port = 27017
user = Some "admin"
password = Some "123"
}
let configuration =
Connection.host config
|> Connection.database database
|> Connection.collection collection
Conventions.create
|> Conventions.add (OptionConvention ())
|> Conventions.add (RecordConvention ())
|> Conventions.build "F# Type Conventions"
Serialization.bson (BagnoSerializationProvider ())
Available options:
eq
- equal to $value,gte
- greater than or equal to $value,gt
- greater than $value,lt
- less than $value,lte
- less than or equal $value,not
- negation of filter,empty
- empty filter.
Additionally filters could be combine via:
&&&
orFilter.and
- equivalent ofand
operator between filters,|||
orFilter.or
- equivalent ofor
operator between filters.
let filter =
Filter.eq (fun (o: BagnoTest) -> o.data) "Bagno"
|> (|||) (Filter.lt (fun (o: BagnoTest) -> o.value) 2137)
Available options:
filter
- getn
results based on passed filter,delete
- delete record based on a filter,deleteMany
- delete records based on a filter,upsert
- update a record based on a filter,insert
- insert record,insertMany
- insert records,getAll
- get all results based on passed filter options.
let filter = Filter.eq (fun (o: BagnoTest) -> o.data) "mango"
let filterOpt = FindOptions<BagnoTest>()
async {
let! result =
Connection.host config
|> Connection.database database
|> Connection.collection collection
|> Query.filter CancellationToken.None filterOpt filter
return result
} |> Async.StartAsTask
Inspired by this old lib which seems to be not maintain any more.