Module: Mongoid::Persistable::Upsertable
- Included in:
- Mongoid::Persistable
- Defined in:
- lib/mongoid/persistable/upsertable.rb
Overview
Defines behaviour for persistence operations that upsert documents.
Instance Method Summary collapse
-
#upsert(options = {}) ⇒ true
Perform an upsert of the document.
Instance Method Details
#upsert(options = {}) ⇒ true
Perform an upsert of the document. If the document does not exist in the database, then Mongo will insert a new one, otherwise the fields will get overwritten with new values on the existing document.
22 23 24 25 26 |
# File 'lib/mongoid/persistable/upsertable.rb', line 22 def upsert( = {}) prepare_upsert() do collection.find(atomic_selector).update(as_document, [ :upsert ]) end end |