Add support for F# types to .net MongoDB.Driver.
- Provide support for F# types for interacting with MongoDB.
- Have an implementation that is fully testable without connecting to a server.
- Isomorphic bson serialization for C# and F#.
Repository origins are:
- Initial repository: https://github.com/mongodb-labs/mongo-fsharp-driver-prototype
- Fork by @visemet (Max Hirschhorn): https://github.com/visemet/FSharp.MongoDB
- This repository: migrated to netstandard 2.1, nullable, adds new features (C#/F# isomomorphic serialization, voption support...)
- build using the top-level solution file (
FSharp.MongoDB.sln
). - you can use
make
with targetbuild
ortest
.
This project targets netstandard2.1
(compatible runtimes).
- If you have a question about the library, then create an issue with the
question
label. - If you'd like to report a bug or submit a feature request, then create an issue with the appropriate label.
- If you'd like to contribute, then feel free to send a pull request.
To serialize F# types, first install this project via NuGet:
Package | Status | Description |
---|---|---|
FSharp.MongoDB | Add F# support to MongoDB.Driver |
On startup you have to register serializers:
MongoDB.Bson.Serialization.FSharp.register()
List<_>
is serialized as an array. Order is preserved.
Set<_>
is serialized as an array. Do not rely on the order.
List<_>
is serialized as an array. Order is preserved.
Seq<_>
is serialized as an array. Order is preserved.
Map<_, _>
is serialized as an object. Do not rely on the order of the keys.
Option<_>
is either serialized as:
null
ifOption.None
object
ifOption.Some
On deserialization, missing value is mapped to None
.
ValueOption<_>
is either serialized as:
null
ifValueOption.ValueNone
object
ifValueOption.ValueSome
On deserialization, missing value is mapped to ValueNone
.
A record is serialized as an `object.
If you want to auto-generate ObjectId
(as the Id of the collection), add [<CLIMutable>]
on the record.
The case of the discriminated union is stored in _t
key.
Each value of the DU is serialized as an object
using its corresponding value name.
NRT are serialized as:
null
ifNull
object
ifNonNull
object
null
when deserializing if value is missing.
The contents of this library are made available under the Apache License, Version 2.0.