Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-4079

Implement positional update operators in LINQ3

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major - P3 Major - P3
    • 2.16.0
    • 2.14.0
    • LINQ3
    • None

    Description

      In LINQ2, you could use the magic number -1 to indicate use of the positional operator, but this no longer works in LINQ3. When calling UpdateOneAsync, UpdateManyAsync, and related operations, the following code works in LINQ2, but fails in LINQ3:

      await collection.UpdateOneAsync(l => l.Id == another.Id && l.AnArrayMember.Any(l => l.Id == anArrayId),
                          Builders<ModelClass>.Update.Set(l => l.AnArrayMember.ElementAt(-1).Deleted, true));
      

      In LINQ3 this fails with the error "Cannot create field '-1' in element [...]". In LINQ2 it successfully translated it into "AnArrayMember.$.Deleted" and the Set command completed fine.

      Attachments

        Activity

          People

            robert@mongodb.com Robert Stam
            james.kovacs@mongodb.com James Kovacs
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: