0

According to the mongo docs, my return object should contain a lastErrorObject, which should indicate if the object is new or old, through updatexisting. I do not see this object. How can I fix my query in order to distinguish between new objects created and found objects?

 db['posts'].find_and_modify({:query=>{"id"=>post_hash["id"]}, :update=>post_hash, :upsert=>true})

What have I done wrong?

JZ.
  • 21,147
  • 32
  • 115
  • 192

1 Answers1

3

The documentation to which you refer is not specific to the ruby driver. Try adding the :full_response=>true option as documented here:

http://api.mongodb.org/ruby/current/Mongo/Collection.html#find_and_modify-instance_method

It should return a hash with the requested document ("value") and a "lastErrorObject" hash with a field "updatedExisting" that you can check. Hope that helps.

jribnik
  • 411
  • 3
  • 5