Exception when using Database name in pipeline match

I want to use Change Stream on the whole replica set, but filtered on database name.
Tried with a pipeline like (e.g.):

var pipeline = new EmptyPipelineDefinition<ChangeStreamDocument<BsonDocument>>()
    .Match(change => change.DatabaseNamespace.DatabaseName.StartsWith("MyDb"));

But exception is thrown when calling MongoClient.Watch(pipeline):
System.NotSupportedException: ‘Serializer for MongoDB.Driver.DatabaseNamespace must implement IBsonDocumentSerializer to be used with LINQ.’

What can I do?

Hi @Magne_Edvardsdal_Ryholt and welcome to MongoDB community forums!!

Could you help me understand in more details on what you are trying to achieve from the above statement.
For example, are you trying to open a change stream on the "MyDb" database?

You can refer to the documentation on working with Change streams in C# for more details.


Thanks for your effort, I am going to have a session with MongoDB’s support service tomorrow and hopefully this issue will be cleared.

I can add the result here in the forum if I think it is of interest to other users as well.

1 Like