BSON :: ObjectId与Mongo :: ObjectID [英] BSON::ObjectId vs Mongo::ObjectID
问题描述
在在线API 中,它们指的是 Mongo: :ObjectID
。
我有需要'mongo'
但仍然无法找到ruby它。例如,我需要通过它的Id找到一个对象,我正在做:
mongo_db ['post']。find ({_id:Mongo :: ObjectID(params [:id])})。next
似乎它找不到Mongo :: ObjectID并导致: NoMethodError - 未定义的Mongo的模块ObjectID:模块:
所以在一段时间后,我开始需要'bson'
并且做
$ {code> mongo_db ['post']。find({_ id:BSON :: ObjectId(params [:id])})。 >
,它工作!
那么BSON :: ObjectId和Mongo :: ObjectID有什么区别,我需要什么要做后者一个工作(我真的需要)?
PS:我有
bson(1.5.2,1.4.1)
作者:Jim Menard,Mike Dirolf,凯尔银行家
主页:http://www.mongodb。 org
安装在(1.5.2):/usr/local/lib64/ruby/gems/1.9.1
(1.4.1):/usr/local/lib64/ruby/gems/1.9.1
BSON的Ruby实现
mongo(1.5.2,1.4.1)
作者:Jim Menard,Mike Dirolf,Kyle Banker
主页:http://www.mongodb.org
安装在(1.5.2):/ usr / local / lib64 / ruby / gem / 1.9.1
(1.4.1):/usr/local/lib64/ruby/gems/1.9.1
MongoDB的Ruby驱动程序
解决方案这里有两处与Ruby驱动程序相关的更改。第一个是:
https:// jira.mongodb.org/browse/RUBY-158
这将ObjectID移动到camel case版本ObjectId。从Mongo命名空间切换到BSON命名空间发生得更早(0.2),请参阅历史记录文件中的最后一个条目:
https://github.com/mongodb/mongo-ruby-driver/blob/master/docs /HISTORY.md
当然,真正的问题是旧的和重要的文档,所以我提交了一个pull请求来更新它:
https://github.com / mongodb / mongo-ruby-driver / pull / 90
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 doingmongo_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
解决方案There are two changes to the Ruby driver that are relevant here. The first is:
https://jira.mongodb.org/browse/RUBY-158
That moved the ObjectID to the "camel case" version ObjectId. The switch from the Mongo namespace to the BSON namespace happened far earlier (0.2), see the last entry in the History file here:
https://github.com/mongodb/mongo-ruby-driver/blob/master/docs/HISTORY.md
The real problem, of course, is old and crufty documentation, so I have submitted a pull request to update it:
https://github.com/mongodb/mongo-ruby-driver/pull/90
这篇关于BSON :: ObjectId与Mongo :: ObjectID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!