Method: Moped::Query#modify
- Defined in:
- lib/moped/query.rb
#modify(change, options = {}) ⇒ Hash
Execute a $findAndModify on the query.
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/moped/query.rb', line 245 def modify(change, = {}) command = { findAndModify: collection.name, query: selector }.merge() command[:sort] = operation.selector["$orderby"] if operation.selector["$orderby"] command[:fields] = operation.fields if operation.fields command[:update] = change unless [:remove] result = session.with(consistency: :strong) do |sess| sess.command(command)["value"] end # Keeping moped compatibility with mongodb >= 2.2.0-rc0 [:upsert] && !result ? {} : result end |