Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-743

UpdateOne and UpdateMany should return error when update parameter is of zero length

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 0.3.0
    • Affects Version/s: 0.1.0
    • Component/s: CRUD
    • Labels:
      None
    • Environment:
      Ubuntu 18.04

      The UpdateOne and UpdateMany methods do not ensure that the update parameter has at least one modifier. Update the ensureDollarKey method to return an error if there are no modifiers provided.

      (original description below)


      mongo.UpdateOne() erases all fields from a document matched by a filter when update interface is bson.D{} with zero length. That behavior is unwanted in my opinion (i've lost some data). Mongo shell acts differently (just returns an error 'the update operation document must contain at least one atomic operator'). I didn't check Update() and UpdateMany() but these ones may act the same as UpdateOne().

        1. after.png
          after.png
          6 kB
        2. before.png
          before.png
          9 kB

            Assignee:
            divjot.arora@mongodb.com Divjot Arora (Inactive)
            Reporter:
            ollevche ollevche
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: