What is the equivalent of runCommand in mongoose?

Viewed 1327
1 Answers

I've found out here that we can use db.db.command :

const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser: true, useUnifiedTopology: true});

var db = mongoose.connection;

db.once('open', function callback () {
    db.db.command({usersInfo: 1}, function (err,result){
        console.log(result);
        mongoose.disconnect();
    });
});
Related