Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get installed mongodb version from mongoose #3654

Closed
aakrem opened this issue Dec 8, 2015 · 2 comments
Closed

get installed mongodb version from mongoose #3654

aakrem opened this issue Dec 8, 2015 · 2 comments

Comments

@aakrem
Copy link

aakrem commented Dec 8, 2015

After taking a look on the links below it seems that the solution is outdated.
node-mongodb-native is not available even in package.json
So anyone has a solution to get the installed mongodb version from mongoose ?
http://stackoverflow.com/questions/15311305/how-to-get-mongodb-version-from-mongoose
http://mongoosejs.com/docs/api.html#index_Mongoose-mongo
https://github.com/Automattic/mongoose/blob/master/package.json

@vkarpov15
Copy link
Collaborator

The solutions aren't outdated. node-mongodb-native isn't in the package.json because node-mongodb-native is the github repo name, the npm package is mongodb.

Here's what mongoose uses internally to determine the version of the mongodb instance its talking to.

  mongoose.connection.on('open', function() {
    var admin = mongoose.connection.db.admin();
    admin.serverStatus(function(err, info) {
      if (err) return cb(err);
      var version = info.version.split('.').map(function(n) { return parseInt(n, 10); });
      cb(null, version);
    });
  });

@ulrichb
Copy link

ulrichb commented Sep 18, 2018

@aakrem You can also use serverInfo() which has a version string property.

console.log((await mongoose.connection.db.admin().serverInfo()).version);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants