Reputation: 6403
I'm using mongoose, and I need to get stats of database.
I know about YourModel.collection.stats()
, but thats just for a collection, I need similar thing, but for the database.
Please dont suggest running the shell command. I want to do it using mongoose.
Upvotes: 2
Views: 4136
Reputation: 411
In addition to MrWhilihog's post, you can also get the data doing the following:
var db = mongoose.connection;
db.db.stats(function (err, stats) {
console.log(stats);
});
This way you are able to get the stats later when your connection is already open.
Upvotes: 0
Reputation: 2646
You can call db.stats
on the mongoose.connection
object:
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
db.db.stats(function(err, stats) {
console.log(stats);
});
});
Upvotes: 8