代码之家  ›  专栏  ›  技术社区  ›  Kyle

通过libmongoc运行shell方法?

  •  1
  • Kyle  · 技术社区  · 6 年前

    我在想是否有可能逃跑 shell methods 通过libmongoc。我能跑 database commands mongoc_client_command . 例如,我可以跑步 listDatabases db.adminCommand( { listDatabases: 1 } ) .

    1. 如果没有,是否有其他api在Mongodb上运行shell命令?
    1 回复  |  直到 6 年前
        1
  •  1
  •   Stennie    6 年前

    mongo shell命令只是底层应用程序的方便包装器 database command API .

    如果调用大多数不带括号的shell帮助程序,则可以看到正在运行的命令。例如, db.adminCommand admin

    > db.adminCommand
    function (obj, extra) {
        if (this._name == "admin")
            return this.runCommand(obj, extra);
        return this.getSiblingDB("admin").runCommand(obj, extra);
    }
    

    通过 libmongoc 你要传递的接口 作为 db_name 参数来运行具有等效结果的命令 db.adminCommand() .