There are several fields in the table, for example:

  • id
  • name
  • value
  • order

it is required to update only value , I do so:

 db.tables.update( { "id", 5 }, { "value" : 10 } ) 

after that only 2 fields are left in the record id and value

Why did the other fields go away, and how to update only 1 field correctly?

    1 answer 1

    Request format update:

     update( <query>, <update>, { upsert: <boolean>, multi: <boolean>, writeConcern: <document>, collation: <document> } ) 

    <query> parameter

    The condition must be: {id: 5} .
    And what you wrote is {id: id, 5: 5}

     db.tables.update({ "id": 5 }, { "value" : 10 }) 

    <update> parameter

    A flat object ( {поле: значение, ...} ) as the second parameter is used to replace the entire document.

    To update part of the document fields, you need to use operators, such as $set :

     db.tables.update({ "id": 5 }, {'$set': {value: 10}})