Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-65423

Cannot create field in element.

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Works as Designed
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None
    • ALL

    Description

      Test scenario:

      db.foo.insertOne({
          "name" : "name",
          "attr": null
      })
       
      db.foo.updateOne(
          {name : "name"},
          {$set : {"attr.key": "key"}}
          )
      //com.mongodb.MongoWriteException: Write operation error on server localhost:27017.
      // Write error: WriteError{code=28, message='Cannot create field 'key' in element {attr: null}', details={}}.
       
       
      db.version() // 5.0.2

      But documentation for $set says:

      If the field does not exist, $set will add a new field with the specified value, provided that the new field does not violate a type constraint. If you specify a dotted path for a non-existent field, $set will create the embedded documents as needed to fulfill the dotted path to the field.

      Attachments

        Activity

          People

            chris.kelly@mongodb.com Chris Kelly
            roman.kazanovskyi@aifora.com Roman Kazanovskyi
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: