<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 如何在 Windows 上安裝 MongoDB > 原文: [https://howtodoinjava.com/mongodb/how-to-install-mongodb-on-windows/](https://howtodoinjava.com/mongodb/how-to-install-mongodb-on-windows/) 在本 MongoDB 教程中,我列出了**在 Windows** 計算機上安裝 MongoDB 的步驟。 另外,我們還將學習與 MongoDB 的啟動和關閉有關的一些基本操作。 ```java Table of Contents 1) Download MongoDB 2) Install MongoDB 3) Create mongo.config Configuration File 4) Start/Shutdown the MongoDB Server 5) MongoDB Windows Service 6) Download/Use MongoDB Java Driver 7) Verify MongoDB Installation ``` ## 1\. 下載 MongoDB Windows 有 MongoDB 的三種構建: 1)Windows Server 2008 R2 版的 MongoDB([下載鏈接](https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-2.6.1.zip "download mongodb for windows server 2008")) 2)Windows 版 64 位 MongoDB([下載鏈接](https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2.6.1.zip "Download mongodb for windows 64 bit")) 3)Windows 版 32 位 MongoDB([下載鏈接](https://fastdl.mongodb.org/win32/mongodb-win32-i386-2.6.1.zip "Download mongodb for windows 32 bit")) 要查找您正在運行的 Windows 版本,請在命令提示符中輸入以下命令:`c:\> wmic os get osarchitecture` [**更多下載選項**](https://www.mongodb.org/downloads "MongoDB downloads")在 MongoDB 的官方網站上提供。 ## 2\. 安裝 MongoDB 上面給定的鏈接將下載 zip 文件,您可以將其直接提取到所選系統中的任何位置。 我已經將它們提取到“`d:/mongodb`”中。 因此,本文中的所有代碼示例以及以后的文章都將引用此位置。 建議在 Windows 環境變量中添加`d:/mongodb/bin`,以便您可以直接在命令提示符下訪問 MongoDB 的命令。 另外,請**在`d:/mongodb`中創建以下目錄** * `D:\mongodb\data` * `D:\mongodb\log` ## 3\. 創建`mongo.config`配置文件 這是前進之前的重要一步。 在位置`d:/mongodb`中創建一個普通文本文件,并將其保存為名稱`mongo.config`。 現在將以下配置選項放置在文件中。 您可以隨意更改選項的值。 ```java ##Which IP address(es) mongod should bind to. bind_ip = 127.0.0.1 ##Which port mongod should bind to. port = 27017 ##I set this to true, so that only critical events and errors are logged. quiet = true ##store data here dbpath=D:\mongodb\data ##The path to the log file to which mongod should write its log messages. logpath=D:\mongodb\log\mongo.log ##I set this to true so that the log is not overwritten upon restart of mongod. logappend = true ##log read and write operations diaglog=3 ##It ensures write durability and data consistency much as any journaling scheme would be expected to do. ##Only set this to false if you don’t really care about your data (or more so, the loss of it). journal = true ``` ## 4\. 啟動/關閉 MongoDB 服務器 要**啟動 MongoDB 服務器**,請在命令提示符下使用以下命令: > `mongod.exe –config d:\mongodb\mongo.config` ```java D:\mongodb\bin>mongod --config D:\mongodb\mongo.config --journal 2014-05-25T16:51:18.433+0530 warning: --diaglog is deprecated and will be removed in a future release 2014-05-25T16:51:18.434+0530 diagLogging level=3 2014-05-25T16:51:18.435+0530 diagLogging using file D:\mongodb\data/diaglog.5381d22e ``` 要在命令提示符下將**連接到 MongoDB** ,請使用以下命令: > `d:\mongodb\bin>mongo` ```java D:\mongodb\bin>mongo MongoDB shell version: 2.6.1 connecting to: test Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user Server has startup warnings: 2014-05-25T16:52:09.158+0530 [initandlisten] 2014-05-25T16:52:09.158+0530 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary. 2014-05-25T16:52:09.158+0530 [initandlisten] ** 32 bit builds are limited to less than 2GB of data (or less with --jour nal). 2014-05-25T16:52:09.158+0530 [initandlisten] ** See http://dochub.mongodb.org/core/32bit 2014-05-25T16:52:09.158+0530 [initandlisten] ``` 要**關閉 MongoDB 服務器**,您必須是授權用戶。 因此,完成認證后,在命令提示符下使用以下命令: > `db.shutdownServer()` ```java > use admin switched to db admin > db.shutdownServer() 2014-05-25T19:55:25.221+0530 DBClientCursor::init call() failed server should be down... 2014-05-25T19:55:25.224+0530 trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed 2014-05-25T19:55:26.225+0530 warning: Failed to connect to 127.0.0.1:27017, reason: errno:10061 No connection could be made b ecause the target machine actively refused it. 2014-05-25T19:55:26.225+0530 reconnect 127.0.0.1:27017 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27017 ( 127.0.0.1), connection attempt failed > quit() D:\mongodb\bin> ``` ## 5\. MongoDB Windows 服務 要安裝窗口服務,請使用以下命令: > `mongod –config D:\mongodb\mongo.config –install` 從命令提示符啟動 Windows 服務: > `net start MongoDB` 從命令提示符處停止 Windows 服務: > `net stop MongoDB` 刪除 Windows 服務 > `mongod –delete` 以下是上述所有四個命令的示例運行: ```java D:\mongodb\bin>mongod --config D:\mongodb\mongo.config --install 2014-05-25T20:07:41.191+0530 warning: --diaglog is deprecated and will be removed in a future release 2014-05-25T20:07:41.192+0530 diagLogging level=3 2014-05-25T20:07:41.193+0530 diagLogging using file D:\mongodb\data/diaglog.53820035 D:\mongodb\bin>net start MongoDB The MongoDB service was started successfully. D:\mongodb\bin>net stop MongoDB System error 109 has occurred. The pipe has been ended. D:\mongodb\bin>mongod --remove 2014-05-25T20:09:32.514+0530 2014-05-25T20:09:32.515+0530 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you wa nt durability. 2014-05-25T20:09:32.515+0530 2014-05-25T20:09:32.518+0530 Trying to remove Windows service 'MongoDB' 2014-05-25T20:09:32.520+0530 Service 'MongoDB' removed ``` ## 6\. 下載/使用 MongoDB Java 驅動 從此[**下載鏈接**](http://central.maven.org/maven2/org/mongodb/mongo-java-driver/2.9.3/mongo-java-driver-2.9.3.jar "mongodb java driver download")下載 MongoDB Java 驅動(`mongo-java-driver-2.9.3.jar`)。 這是一個 jar 文件,您需要在要使用 MongoDB 的項目的`libpath`文件夾中的`classpath/copy`中包含該文件。 ## 7\. 驗證 MongoDB 安裝 要驗證是否已安裝 MongoDB 并正常工作,請執行以下程序: ```java package examples.mongodb.install; import java.net.UnknownHostException; import java.util.List; import com.mongodb.MongoClient; public class VerifyMongoDBInstallation { public static void main(String[] args) throws UnknownHostException { MongoClient mongo = new MongoClient("localhost", 27017); List<String> dbs = mongo.getDatabaseNames(); for (String db : dbs) { System.out.println(db); } } } Output: local admin ``` 全部完成 **MongoDB Windows 安裝**,啟動和關閉操作。 接下來,我們將學習一些 CRUD 操作。 跟著我保持關注。 學習愉快!
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看