We’re using the MongoHQ addon on Heroku, with the Mongoid 3.0 adapter. The addon plans come with a size limit, and Mongo will silently fail writing when the DB limit has been reached (unless configured for safe mode–in which case it’ll throw exceptions).
I’m trying to query from within the app how close we are and send an alert if we’ve reached the limit. How can I run something like the db.stats() command but using Mongoid?
I’ve found out how to do this in Mongoid 3.x which uses Moped as driver, not the Ruby driver from 10gen.
It was the author of Moped himself who answered a github issue raised on the matter.
This will return the same results as
db.stats()from the Mongo console. As an additional bonus, if the collection is capped, there’ll be a flag in the return values indicating that.