What am I doing wrong here? I know the _id is in the database but I get empty result.
@b = coll.find("_id" => "4db2ebee90036f010b000001")
Thanks
Use this:
coll.find(:_id => BSON::ObjectId('4db2ebee90036f010b000001')).each do |data|
puts data.inspect
end
Using, Ruby version 2.3.1p112, mongo (gem) 2.4.2 and BSON (gem) 4.2.2
The following worked for me
client = Mongo::Client.new(['127.0.0.1:3001'], :database=>'dbname')
collection = client[:users]
user = collection.find({_id:'XY3h5R7aJkh5FxFhJ'}).first
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With