Update document issue

I tried some update operators

Here is my document:
db.movieDetails.find( {“title”: “West Side Story”}).pretty()

This was ok
db.movieDetails.updateOne({“title”: “West Side Story”},{ $inc : { “runtime”: 1 }})

But not this (this is written like this is documentation: update instead of updateOne)

db.movieDetails.update( {“title”: “West Side Story”}, { $inc : { “runtime”: 1 } } )
WriteResult({ “nMatched” : 1, “nUpserted” : 0, “nModified” : 1 })

Is it a documentation issue ?

Worst than this… I also made an easy to do mistake ( inc$ instead of the modifier $inc)

db.movieDetails.update( {“title”: “West Side Story”}, { inc$ : { “runtime”: 1 } } )

My whole document were replaced by an object name $inc !
How can I protect myself for such errors ? (other than unit testing every single line of code)

Both update and updateOne are valid. The first one update all documents matching the query. While updateOne update only the first document matching the query.

Hi @Denis_Gilbert_55813,

To avoid this kind of mistakes in a standalone environment, you can use either use Schema Validation or Document Versioning.

Hope it helps!

Shubham Ranjan
Curriculum Services Engineer