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

Implement positional update operators in LINQ3

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.16.0
    • Affects Version/s: 2.14.0
    • Component/s: LINQ3
    • Labels:
      None
    • Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      We should document all the positional update operators with code examples:
      x.A.FirstMatchingElement() => "A.$"
      x.A.AllElements() => "A.$[]"
      x.A.AllMatchingElements("identifier") => "A.$[identifier]"

      We should add this to our UpdateOne and/or UpdateMany documentation as an advanced usage. We can mirror the server examples and show how to write these using C# syntax:
      https://www.mongodb.com/docs/manual/reference/operator/update/positional/
      https://www.mongodb.com/docs/manual/reference/operator/update/positional-all/
      https://www.mongodb.com/docs/manual/reference/operator/update/positional-filtered/

      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      Yes.

      3. Which versions of the driver/connector does this apply to?
      2.16.0 and later. Ideally add this to 2.19 and later docs, but minimally add it to latest.

      Show
      1. What would you like to communicate to the user about this feature? We should document all the positional update operators with code examples: x.A.FirstMatchingElement() => "A.$" x.A.AllElements() => "A.$[]" x.A.AllMatchingElements("identifier") => "A.$ [identifier] " We should add this to our UpdateOne and/or UpdateMany documentation as an advanced usage. We can mirror the server examples and show how to write these using C# syntax: https://www.mongodb.com/docs/manual/reference/operator/update/positional/ https://www.mongodb.com/docs/manual/reference/operator/update/positional-all/ https://www.mongodb.com/docs/manual/reference/operator/update/positional-filtered/ 2. Would you like the user to see examples of the syntax and/or executable code and its output? Yes. 3. Which versions of the driver/connector does this apply to? 2.16.0 and later. Ideally add this to 2.19 and later docs, but minimally add it to latest.

      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.

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

              Created:
              Updated:
              Resolved: