lib/mongo_mapper/plugins/querying.rb in mongo_mapper-0.14.0 vs lib/mongo_mapper/plugins/querying.rb in mongo_mapper-0.15.0
- old
+ new
@@ -136,15 +136,21 @@
@_new = false
method = options.delete(:persistence_method) || :save
update = to_mongo
query_options = Utils.get_safe_options(options)
+ if query_options.any?
+ collection = self.collection.with(write: query_options)
+ else
+ collection = self.collection
+ end
+
case method
when :insert
- collection.insert(update, query_options)
+ collection.insert_one(update, query_options)
when :save
- collection.save(update, query_options)
+ collection.update_one({:_id => _id}, update, query_options.merge(upsert: true))
when :update
update.stringify_keys!
id = update.delete("_id")
@@ -166,10 +172,10 @@
update_query = {}
update_query["$set"] = set_values if set_values.any?
update_query["$unset"] = unset_values if unset_values.any?
if update_query.any?
- collection.update(find_query, update_query, query_options)
+ collection.update_one(find_query, update_query, query_options)
end
end
end
end
end
\ No newline at end of file