0

I am combining both mongomapper and mongo driver in my project. I had to downgrade version of mongo driver, cause mongomapper depends on 1.12.5. Unfortunately I've got problem with update({search_hash}, {update_hash}, upsert: false), because it will create new document if searched document doesn't exist. Also, in documentation, no information about optional parameters of update is supplied.

Here is documentation: http://api.mongodb.org/ruby/1.1.5/Mongo/Collection.html

And some code here:

class MongoConnector


 attr_reader :type, :collection

  def initialize(db_params, type)
    @type = type
    db = Mongo::Connection.new(connection_uri[:host], connection_uri[:port])
    @collection = db[db_params[:key]][db_params[:collection]]
  end

  def update(id, update_query)
    collection.update({ _id: bson_id(id) }, update_query, upsert: false)
  end

 private

 def bson_id(id)
    BSON::ObjectId(id)
  end
end
Robs
  • 153
  • 2
  • 10

0 Answers0