MongoDB ruby driver update single field

Viewed 55

https://docs.mongodb.com/ruby-driver/v2.14/tutorials/ruby-driver-crud-operations/#updating

I' been doing this

videos.find({"id": "c024f2bd"}).update_one({"title": "this is testing"})

When i look over the database it replace the entire document with just this field, my other field were all gone and empty. How can i update just single field? i've read the document it doesn't seem to have option parameter where i can define update field only don't replace.

1 Answers

You should use $set. Try this:

videos.update_one({"id": "c024f2bd"}, {"$set": {"title": "this is testing"}})
Related