Using indexOf(-1) for Positional Operator does not work in bulk operations

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Won't Fix
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.4.2
    • Component/s: LINQ
    • None
    • None
    • Fully Compatible

      When attempting to use indexOf(-1) in a bulk operation update, the produced mongo query does not contain the "$" positional operator resulting in the query throwing an error.

      Example

      bulk.Find(Query<Users>.Where(user => user.FavoriteColors.Any(f => f.Name == "green")))
      .UpdateOne(Update<Users>.Set(user => user.FavoriteColors.IndexOf(-1).Name, "blue");

      Results in {$set:

      {"user.favoriteColors.-1.name":"blue"}

      which throws and error.

      Workaround

      bulk.Find(Query<Users>.Where(user => user.FavoriteColors.Any(f => f.Name == "green")))
      .UpdateOne(Update.Set("user.favoriteColors.$.name", "blue");

      NOTE: It would be nice if indexOf(-1) could be supported across ALL query builders, including legacy, current, and .net core.

      References:
      https://jira.mongodb.org/browse/CSHARP-531
      https://github.com/mongodb/mongo-csharp-driver/blob/master/tests/MongoDB.Driver.Legacy.Tests/Operations/BulkWriteOperationTests.cs

            Assignee:
            Dmitry Lukyanov (Inactive)
            Reporter:
            Kalarrs Topham
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: