Does someone know why I have to toString my guid when I try to filter a MongoDB query with bson documents?


System.Guid is a byte array actually and it requires additional transformation to be converted to the string representation.
You may try to use byte array as a key in the database but this require to rebuild a db I believe
Json/bson do not have a Guid data type. Instead Guids are usually stored as strings. At some point your Guid would need to be converted to this string. What MongoDB library are you using? Perhaps you could register a Guid => string converter.
Edit: It turns out that bson actually does have a UUID data type (while Json does not). If the document you want to search for is a json document (with Guid encoded as string), then a bson binary encoded UUID/Guid would not match.
GUID isn’t typically a data type and it’s alphanumeric.
So best solution is tostring it?
C# devs
null reference exceptions

source