V
V
Vladimir Solovyov2014-06-24 01:07:20
MongoDB
Vladimir Solovyov, 2014-06-24 01:07:20

MongoDB: Does update overwrite same values?

There is a code

db.test.test->insert ({_id: 1, key1: 'value1'})
db.test.test->update ({_id: 1}, {$set: {key1: 'value1'}})

Will the "new" value be written to disk or not? I didn't find it in the documentation.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Z
zed, 2014-06-27
@Cttr

Apparently, the record is not being made:

D:\MongoDB>mongo --verbose
MongoDB shell version: 2.6.3
...
> db.test.insert({_id:1, key1:"value1"})
WriteResult({ "nInserted" : 1 })
> db.test.update({_id:1}, {$set:{key1:"value1"}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
> db.test.update({_id:1}, {$set:{key1:"value2"}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

P
Puma Thailand, 2014-06-24
@opium

Well, how could they not find it there in black and white at the very beginning it is written

A
antes, 2014-06-26
@antes

Set the upsert parameter to true and if the element is found, it is overwritten, if not, it is inserted. Read more here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question