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

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Minor - P4
    • 1.4
    • Affects Version/s: 1.3.1
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • 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 Stam
            Reporter:
            Gordon ML
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: