Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-6515

document update sample need acorrection

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Cannot Reproduce
    • Icon: Minor - P4 Minor - P4
    • 01112017-cleanup
    • mongodb-3.0
    • manual
    • None
    • CentOS 7.1, MongoDB shell version: 3.0.6, AWS EC2

    Description

      The issue was found in this document url: https://docs.mongodb.org/getting-started/shell/update/#update-data-with-the-mongo-shell

      Where "Replace a Document" section the sample code not working:
      in the document"
      "After the following update, the modified document will only contain the _id field, name field, the address field. i.e. the document will not contain the restaurant_id, cuisine, grades, and the borough fields.

      db.restaurants.update(

      { "restaurant_id" : "41704620" }

      ,
      {
      "name" : "Vella 2",
      "address" :

      { "coord" : [ -73.9557413, 40.7720266 ], "building" : "1480", "street" : "2 Avenue", "zipcode" : "10075" }

      }
      )
      "
      the document did not get replaced but only the fields updated. Adding "restaurant_id" : "41704620" in the new document section, the document got replaced. The sample code should be as following:

      db.restaurants.update(

      { "restaurant_id" : "41704620" }

      ,
      {
      "name" : "Vella 2",
      "address" :

      { "restaurant_id" : "41704620", "coord" : [ -73.9557413, 40.7720266 ], "building" : "1480", "street" : "2 Avenue", "zipcode" : "10075" }

      }
      )

      Attachments

        Activity

          People

            kay.kim@mongodb.com Kay Kim (Inactive)
            fngyjx John Du
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              8 years, 15 weeks, 1 day ago