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

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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Major - P3 Major - P3
    • None
    • 2.4.2
    • Linq
    • None
    • Fully Compatible

    Description

      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

      Attachments

        Activity

          People

            dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
            exocom Kalarrs Topham
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: