In online API they are referring to Mongo::ObjectID
.
I have require 'mongo'
but still ruby fails to find it. For instance, I need to find an object by its Id and I'm doing:
mongo_db['post'].find({_id: Mongo::ObjectID(params[:id])}).next
and it seems that it can't find Mongo::ObjectID and results in: NoMethodError - undefined method ``ObjectID' for Mongo:Module:
So after some time I started to require 'bson'
and doing
mongo_db['post'].find({_id: BSON::ObjectId(params[:id])}).next
and it worked!
So what's the difference between BSON::ObjectId and Mongo::ObjectID and what do I need to do to make the latter one work (and do I really need to)?
PS: I've got
bson (1.5.2, 1.4.1)
Authors: Jim Menard, Mike Dirolf, Kyle Banker
Homepage: http://www.mongodb.org
Installed at (1.5.2): /usr/local/lib64/ruby/gems/1.9.1
(1.4.1): /usr/local/lib64/ruby/gems/1.9.1
Ruby implementation of BSON
mongo (1.5.2, 1.4.1)
Authors: Jim Menard, Mike Dirolf, Kyle Banker
Homepage: http://www.mongodb.org
Installed at (1.5.2): /usr/local/lib64/ruby/gems/1.9.1
(1.4.1): /usr/local/lib64/ruby/gems/1.9.1
Ruby driver for the MongoDB