簡體   English   中英

我們如何使用帶有身份驗證的ProcessBuilder(java)將mongo作為進程啟動

[英]How can we start mongo as process using ProcessBuilder (java) with authentication

我們如何使用帶有身份驗證的ProcessBuilder(java)將mongo作為進程啟動。

我的mongo服務器已啟用身份驗證。 以前的代碼是。

   String osName = System.getProperty("os.name");
   String executableName = (osName != null && osName.contains("indows")) ? "mongo.exe" : "mongo";
   String[] commandLine = new String[]{
       PathUtil.findExecutable(executableName),
            "localhost" + ":" + "27017" + "/" + "test", getScriptPath(path)
   };

   ProcessBuilder processBuilder = new ProcessBuilder(commandLine);
   processBuilder.directory(new File(getScriptPath(path)).getParentFile());
   processBuilder.redirectErrorStream(true);

   Process process = processBuilder.start();

如何在身份驗證中添加用戶名/密碼?

像這樣將用戶/密碼添加到mongodb url

String[] commandLine = new String[]{
    PathUtil.findExecutable(executableName), "user:password@localhost:27017/test", getScriptPath(path)
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM