Work with Array position operator and variables both

Hi, @alexov_inbox,

The JSON string provided to the BsonDocument.Parse method is invalid. Field names in JSON must be quoted, though many parsers allow unquoted field names if they do not contain special characters such as ., [, and ]. The following properly-quoted JSON does parse correctly, but I believe the resulting MQL is invalid:

var pipeline = new[]
        {
            BsonDocument.Parse("{ $addFields : { 'm.$[e].MessageSeqMax': { $sum: ['$m.$[e].MessageSeqMax', 1] }} }"),
        };

Regarding Update 1, this is a problem in your findAndModify command, not in the .NET/C# driver. I would suggest investigating how to express this in the mongosh shell. Providing a self-contained repro (including some simplified sample data) and explanation of what you’re attempting to accomplish would be very helpful in understanding what you are trying to achieve.

Sincerely,
James

2 Likes