MongoDB Ruby driver 2.0 series available

257 views
Skip to first unread message

Emily S

unread,
Mar 26, 2015, 12:26:25 PM3/26/15
to mongod...@googlegroups.com
The MongoDB Ruby team is happy to announce that the 2.0 series of the Ruby driver has been released. This is a complete rewrite of the driver with many API and design improvements.

It has a number of backwards incompatible changes so please see the new API documentation.
http://api.mongodb.org/ruby/
http://docs.mongodb.org/ecosystem/drivers/ruby/


It can be installed using RubyGems:

gem install mongo


Give it a try and let us know what you think!

If you find any issues, please open a ticket in the JIRA Ruby driver project: https://jira.mongodb.org/browse/RUBY

- Emily and Durran

Mahmood Shafeie Zargar

unread,
Mar 27, 2015, 5:15:37 PM3/27/15
to mongod...@googlegroups.com
Hi,

I just set up a new development environment and I noticed that the new gem was installed by default. First things first, I need to load these gems in the following order so that I don't get any error or warning (I'm on Ruby 2.2.0p0):

require 'date'
require 'bson'
require 'mongo'

If I miss 'date', I get an error. If I miss 'son', I get warnings. This shouldn't be the expected behaviour of the gem.

I understand that the new API is not compatible with the old one, and I have managed modifying all my scripts, except that I can't figure out how to work with DBRefs. What has happened to DBRef? If it is missing I will have to revert all the work and go back to the older version.

Mahmood
Message has been deleted

Emily S

unread,
Mar 30, 2015, 12:36:41 PM3/30/15
to mongod...@googlegroups.com

Hi Mahmood

Thanks for pointing this out. I've looked into it, and found that RubyGems removed a dummy Date class in version 2.4, which is bundled with Ruby 2.2.0, as per this commit.

I just added a line to require 'date' in our Date class to account for this and released as bson 3.0.1

You shouldn't have to explicitly require 'bson' as it's a dependency of the mongo gem.

So try out doing the following in IRB now that bson 3.0.1 is released

require 'mongo'
 

and let me know if it works for you.

CORRECTION:

'DBPointer' in the BSON spec is deprecated. The DBRef type is not deprecated but is not currently available in the bson gem 2.0. It will be added soon for backwards compatibility.

Thanks and let me know if you have any more questions!

Emily

Emily S

unread,
Mar 30, 2015, 12:52:19 PM3/30/15
to mongod...@googlegroups.com
We created a ticket for adding DBRef to bson if you want to follow it:

Chris Heald

unread,
Apr 2, 2015, 12:10:24 PM4/2/15
to mongod...@googlegroups.com
I'm attempting to get started on branches of Plucky and MongoMapper which use the 2.0 driver, but I'm running into issues right out of the gate:

2.0.0-p353 :001 > require 'mongo'
 => true
2.0.0-p353 :002 > c = Mongo::Client.new(["localhost:27017"]).use("test")
D, [2015-04-02T09:07:17.024133 #27683] DEBUG -- : MONGODB | Adding localhost:27017 to the cluster. | runtime: 0.0041ms
D, [2015-04-02T09:07:17.025454 #27683] DEBUG -- : MONGODB | COMMAND | namespace=admin.$cmd selector={:ismaster=>1} flags=[] limit=-1 skip=0 project=nil | runtime: 1.0478ms
D, [2015-04-02T09:07:17.025573 #27683] DEBUG -- : MONGODB | Address family not supported by protocol - connect(2) | runtime: 0.0024ms
 => #<Mongo::Client:0x19102720 cluster=localhost:27017>
2.0.0-p353 :003 > c.database.collections
D, [2015-04-02T09:07:23.231450 #27683] DEBUG -- : MONGODB | COMMAND | namespace=admin.$cmd selector={:ismaster=>1} flags=[] limit=-1 skip=0 project=nil | runtime: 0.2856ms
D, [2015-04-02T09:07:23.231570 #27683] DEBUG -- : MONGODB | Broken pipe | runtime: 0.0019ms
D, [2015-04-02T09:07:23.731932 #27683] DEBUG -- : MONGODB | COMMAND | namespace=admin.$cmd selector={:ismaster=>1} flags=[] limit=-1 skip=0 project=nil | runtime: 0.6640ms
D, [2015-04-02T09:07:23.732103 #27683] DEBUG -- : MONGODB | Address family not supported by protocol - connect(2) | runtime: 0.0019ms
D, [2015-04-02T09:07:24.231653 #27683] DEBUG -- : MONGODB | COMMAND | namespace=admin.$cmd selector={:ismaster=>1} flags=[] limit=-1 skip=0 project=nil | runtime: 0.2983ms
D, [2015-04-02T09:07:24.231779 #27683] DEBUG -- : MONGODB | Broken pipe | runtime: 0.0019ms
D, [2015-04-02T09:07:24.732163 #27683] DEBUG -- : MONGODB | COMMAND | namespace=admin.$cmd selector={:ismaster=>1} flags=[] limit=-1 skip=0 project=nil | runtime: 0.7045ms
D, [2015-04-02T09:07:24.732294 #27683] DEBUG -- : MONGODB | Address family not supported by protocol - connect(2) | runtime: 0.0019ms
D, [2015-04-02T09:07:25.231887 #27683] DEBUG -- : MONGODB | COMMAND | namespace=admin.$cmd selector={:ismaster=>1} flags=[] limit=-1 skip=0 project=nil | runtime: 0.3157ms
D, [2015-04-02T09:07:25.232060 #27683] DEBUG -- : MONGODB | Broken pipe | runtime: 0.0019ms

It'll sit there and spin on that "broken pipe" issue indefinitely. The mongod instance it's communicating with is a mongod-2.6.6 instance; is the new driver only compatible with 3.0 or something?

Emily S

unread,
Apr 6, 2015, 7:24:36 AM4/6/15
to mongod...@googlegroups.com
Hi Chris

You seem to be connecting to the client correctly. The 2.x series of the driver supports back to server version 2.4 so that shouldn't be the issue.

I'm guessing that maybe you have something in your /etc/hosts that's preventing the client from connecting using the "localhost" string. Have you tried specifying the seed as "127.0.0.1:27017" ?

c = Mongo::Client.new(["127.0.0.1:27017"]).use("test")

Check out your /etc/hosts and try the above and let me know if that resolves the issue.

Thanks

Emily

Emily S

unread,
Apr 9, 2015, 6:43:26 AM4/9/15
to mongod...@googlegroups.com
Hi Chris

I've just committed some changes to master that may resolve the issue you were seeing. Would you mind trying out the code from master?
Thanks

Emily

mikeni

unread,
Apr 23, 2015, 5:43:24 AM4/23/15
to mongod...@googlegroups.com
In my rails console, I am loading the mongo::client however it is outputting

D, [2015-04-23T01:51:00.677707 #1467] DEBUG -- : MONGODB | COMMAND | namespace=admin.$cmd selector={:ismaster=>1} flags=[] limit=-1 skip=0 project=nil | runtime: 0.3562ms

D, [2015-04-23T01:51:10.678599 #1467] DEBUG -- : MONGODB | COMMAND | namespace=admin.$cmd selector={:ismaster=>1} flags=[] limit=-1 skip=0 project=nil | runtime: 0.4640ms

D, [2015-04-23T01:51:20.679812 #1467] DEBUG -- : MONGODB | COMMAND | namespace=admin.$cmd selector={:ismaster=>1} flags=[] limit=-1 skip=0 project=nil | runtime: 0.3400ms

D, [2015-04-23T01:51:30.684039 #1467] DEBUG -- : MONGODB | COMMAND | namespace=admin.$cmd selector={:ismaster=>1} flags=[] limit=-1 skip=0 project=nil | runtime: 0.3641ms

constantly

is this normal?

Emily S

unread,
Apr 23, 2015, 7:03:40 AM4/23/15
to mongod...@googlegroups.com
Yes.
You can change the logging level by doing the following:

Mongo::Logger.logger.level = Logger::WARN

Mark Thomson

unread,
Apr 23, 2015, 4:42:09 PM4/23/15
to mongod...@googlegroups.com
Where is the API documentation for this new version? It's not here: http://api.mongodb.org/ruby/2.0.2/

Mark Thomson

unread,
Apr 23, 2015, 8:01:44 PM4/23/15
to mongod...@googlegroups.com
I take it back... the documentation is there, just carefully hidden via some links in the top right hand corner.

Shawn Stephens

unread,
May 29, 2015, 2:05:15 PM5/29/15
to mongod...@googlegroups.com
Can the 2.0.x driver be used with MongoDB Server 2.2? Can it be used with MongoDB Server 1.8?


On Thursday, March 26, 2015 at 11:26:25 AM UTC-5, Emily S wrote:

Emily S

unread,
May 29, 2015, 2:23:29 PM5/29/15
to mongod...@googlegroups.com

mikeni

unread,
Jun 1, 2015, 6:20:59 AM6/1/15
to mongod...@googlegroups.com
Emily,

I have upgraded my ruby driver to 2.0 and when fetching count 

collection.find.count

this seems to take much longer than the ruby driver before,

Is there another method to get count on a collection without doing a query first?

Michael

Emily S

unread,
Jun 8, 2015, 5:14:00 AM6/8/15
to mongod...@googlegroups.com

Hi Michael


When you call #find on a collection, it doesn't actually execute the query; it returns a Collection::View object on which #count can be called. The #find method is used to define the count criteria. 


For example, see this documentation:


http://docs.mongodb.org/ecosystem/tutorial/ruby-driver-tutorial/#additional-query-operations


Thus, you aren't doing a query and a count. Calling #count just runs the count command with the defined query.


Regarding the performance difference; Are you running #count with the same exact criteria in the old driver as you are in the new driver? Would you mind sending me the lines of code you are using to do the count in both the new and old drivers?


Thanks

Emily

Reply all
Reply to author
Forward
0 new messages