# Looking for library for serializing F# types to Mongo BSON

**URL:** <https://forums.fsharp.org/t/looking-for-library-for-serializing-f-types-to-mongo-bson/3695>\
**Category:** General\
**Created:** [July 31, 2024, 8:33am UTC](https://forums.fsharp.org/t/looking-for-library-for-serializing-f-types-to-mongo-bson/3695 "2024-07-31T08:33:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadiba](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@kadiba](https://forums.fsharp.org/u/kadiba)\
**Post date:** [July 31, 2024, 8:33am UTC](https://forums.fsharp.org/t/looking-for-library-for-serializing-f-types-to-mongo-bson/3695/1 "2024-07-31T08:33:43Z")

</div>

Hi, I am looking for a library for (de)serializing F# types such as lists, records, and discriminated unions to and from MongoDB BSON.

The ones I’ve found are not complete or have bugs. I wonder what other people use for this?

I’ve looked at

- [GitHub - ruxo/MongoDB.FSharp: Silent utilities to make the official MongoDB driver feel natural to work with in F#](https://github.com/ruxo/MongoDB.FSharp) which has a bug in the serialization of discriminated unions and doesn’t support sets or maps.
- [NamelessInteractive.FSharp/NamelessInteractive.FSharp.MongoDB at master · NamelessInteractive/NamelessInteractive.FSharp · GitHub](https://github.com/NamelessInteractive/NamelessInteractive.FSharp/tree/master/NamelessInteractive.FSharp.MongoDB) which is very old and doesn’t work with .NET 8. I’ve made a fork and tested it, but it cannot handle sets of record types.

As I see it, I have the following options:

- Ideally, wait for someone here to reply with the battle-tested library that they use
- Manually write serializers for the types I need
- Fork and fix one of the existing libraries or create a new one
- Perhaps use one of the FSharp → JSON libraries and then convert the JSON into BSON, if that works.

Looking forward to hearing back from you, thanks in advance 😊

---

<div class="post-metadata">

**Author:** ![kadiba](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@kadiba](https://forums.fsharp.org/u/kadiba)\
**Post date:** [August 2, 2024, 10:57am UTC](https://forums.fsharp.org/t/looking-for-library-for-serializing-f-types-to-mongo-bson/3695/2 "2024-08-02T10:57:47Z")

</div>

I ended up making my own with inspiration from the two listed. I’ll make it public when it is more solidified.

---

<div class="post-metadata">

**Author:** ![gopherchucks](https://avatars.discourse-cdn.com/v4/letter/g/35a633/32.png) [@gopherchucks](https://forums.fsharp.org/u/gopherchucks)\
**Post date:** [August 6, 2024, 1:45am UTC](https://forums.fsharp.org/t/looking-for-library-for-serializing-f-types-to-mongo-bson/3695/3 "2024-08-06T01:45:58Z")

</div>

That’s awesome! Im excited to see how it pans out. I’m using F# and MongoDB as well for a personal project and ran into the same issues. I ended up going the route of least resistance, using classes where I interact with MongoDB and then converting to the F# types that make up my domain.
