Ruby Mongo Driver - Find_by_Id Ruby Mongo Driver - Find_by_Id mongodb mongodb

Ruby Mongo Driver - Find_by_Id


Use this:

coll.find(:_id => BSON::ObjectId('4db2ebee90036f010b000001')).each do |data|    puts data.inspect end


@b will contain a cursor, not the result. You also need to use an object id proper.

You probably want this:

@b = coll.find_one(:_id => BSON::ObjectId('4db2ebee90036f010b000001'))


With Ruby 1.9.3 and mongoid 3.0.19

@coll = Coll.find( hash["_id"] )

or

@coll = Coll.find( "511296d2dfa18f07fa000009" )

find the record. Will only ever be one, _id is the primary key, it can never be double.