We are planning to use mongo change streams to push data from MongoDB to Elastic in near real time. The POC we did was for single tenant database explicitly specifying the database name and collection name for which we want to watch the changes.
I don’t like the way of using a for loop to go over all databases or open multiple connections in parallel. Having single opened connection is better. I see that it does support regex for dynamic mapping, something like below. Are there any other better options?
var regexPattern = "databasename_[a-zA-Z0-9-]+";
var pipeline = new BsonDocumentPipelineStageDefinition<ChangeStreamDocument<BsonDocument>, ChangeStreamDocument<BsonDocument>>(
new[]
{
BsonDocument.Parse("{ $match: { 'ns': { $regex: '" + regexPattern + @"\.Records$' } } }")
});