Reputation: 868
I have a Rails app with MongoDB. I need to dynamically display current MongoDB version on the status webpage. It's important for my client to know whether it's 3.0
, 3.2
or 3.4
version.
However, I can't find this value anywhere. I'm using pry
to debug the connection details and I've already tried any relevant public method from Mongoid
and Mongo
class hierarchy without success.
The canonical way to do this with pure MongoDB is db.version()
, but it seems there is no way to send this raw query with Mongoid.
Upvotes: 4
Views: 1999
Reputation: 332
You should do the following call (Mongoid 5+):
Mongoid.default_client.command(buildInfo: 1).first[:version]
Or, in earlier versions:
Mongoid.default_session.command(buildinfo: 1)["version"]
(Answer updated according to @yeasayer comment)
Upvotes: 10