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.
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)
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