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

FindAndModify throws InvalidOperationException if upsert is true and query is null and collection is empty

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.4
    • Affects Version/s: 1.3.1
    • Component/s: None

      When performing an upsert to increment a counter value, as follows:

      MongoDatabase database = MongoDatabase.Create("mongodb://localhost/test");
      database.GetCollection("test").FindAndModify(null, SortBy.Null, Update.Inc("Counter", 1), true, true)

      FindAndModify throws the following exception only when the collection is empty

      System.InvalidOperationException
      Command 'findAndModify' failed: exception: upsert mode requires query field (response:

      { "errmsg" : "exception: upsert mode requires query field", "code" : 13330, "ok" : 0.0 }

      )

      This is inconsistent behaviour: no exception is thrown if the document exists (works as expected); and the mongo shell allows the same command in javascript.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            gordonml Gordon ML
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: