lib/voteable_mongo/voting.rb in voteable_mongo-0.9.1 vs lib/voteable_mongo/voting.rb in voteable_mongo-0.9.2
- old
+ new
@@ -25,16 +25,19 @@
unvote_query_and_update(options)
else
new_vote_query_and_update(options)
end
- # If votee exits or need to update parent
- # use Collection#find_and_modify to retrieve updated votes data and parent_ids
- doc = voteable_collection.find_and_modify(
- :query => query,
- :update => update,
- :new => true
- )
+ # http://www.mongodb.org/display/DOCS/findAndModify+Command
+ begin
+ doc = voteable_collection.find_and_modify(
+ :query => query,
+ :update => update,
+ :new => true
+ )
+ rescue Mongo::OperationFailure
+ doc = nil
+ end
if doc
update_parent_votes(doc, options) if options[:voteable][:update_parents]
# Update new votes data
options[:votee].write_attribute('votes', doc['votes']) if options[:votee]