【问题标题】:What is the equivalent of runCommand in mongoose?mongoose 中的 runCommand 等价物是什么?
【发布时间】:2020-03-23 00:30:41
【问题描述】:

在 MongoDB shell 中,您可以使用 db.runCommand(...)。例如显示 mongoDB 用户:

> db.runCommand({usersInfo:1})
....
list of users
....

这对User management commands很有用

中的等价物是什么?

【问题讨论】:

    标签: mongoose javascript node.js mongodb mongoose


    【解决方案1】:

    我发现here 我们可以使用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();
        });
    });
    

    【讨论】:

      猜你喜欢
      • 2014-05-08
      • 2014-06-12
      • 1970-01-01
      • 2022-11-28
      • 2021-06-19
      • 2012-07-20
      • 2023-03-30
      • 2011-04-08
      • 2014-09-24
      相关资源
      最近更新 更多