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?
I asked this question on Mongoid group and this was the best response:
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/Cl...
From there, you can use the MongoDB Ruby driver API directly.
http://api.mongodb.org/ruby/current/file.TUTORIAL.html#
Also, you can access the record collection using ModelName.collection.
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