How to directly access MongoDB API from Mongoid?

252 views
Skip to first unread message

Volkan Unsal

unread,
Jan 24, 2011, 6:31:18 AM1/24/11
to Mongoid
I'd like to use the addToSet method of MongoDB, but Mongoid doesn't
currently support this yet. Is there a way of directly accessing the
MongoDB driver from my Rails model?

Brian Ploetz

unread,
Jan 24, 2011, 9:46:38 AM1/24/11
to Mongoid
Assuming your model object is a Mongoid::Document, simply call the
"db" method on it to get a handle to the Mongo::DB object that Mongoid
is using under the hood.

http://rdoc.info/github/mongoid/mongoid/master/Mongoid/Collections/ClassMethods#db-instance_method

From there, you can use the MongoDB Ruby driver API directly.

http://api.mongodb.org/ruby/current/file.TUTORIAL.html#

Durran Jordan

unread,
Jan 24, 2011, 9:49:54 AM1/24/11
to mon...@googlegroups.com
Model.collection will get you the collection object.

2011/1/24 Volkan Unsal <spocks...@gmail.com>

Kieran P

unread,
Jan 24, 2011, 2:18:21 PM1/24/11
to mon...@googlegroups.com
In addition to the response by Durran, there is a ticket for adding addToSet functionality.


Regards
Kieran
Reply all
Reply to author
Forward
0 new messages