Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-2288

updateOne semantic is not as expected

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 3.2.0
    • API
    • None

    Description

      The first way to perform an update to a document would be (from my point of view) something like this

         Document tempDoc = new Document();
         tempDoc.put("value", "new value");
         collection.updateOne(Filters.eq("_id", 1), tempDoc);
      

      but this leads to

      Exception in thread "main" java.lang.IllegalArgumentException: Invalid BSON field name value

      I have to wrap my update in another document

      Document tempDoc = new Document();
          tempDoc.put("value", "new value");
          Document tempUpdateOp = new Document("$set", tempDoc);
          collection.updateOne(Filters.eq("_id", 1), tempUpdateOp);
      

      This is strange because there is no need to wrap it. For the purpose of replacing a document there is another method replaceOne. Why do I have to wrap my update into another document for the updateOne call?

      Attachments

        Activity

          People

            Unassigned Unassigned
            stephan@frind.de Stephan Frind
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: