MongoDBデータベースパスの交換

5042 ワード

最近MongoDBの勉強を始めたばかりで、インストール後にデータベースを作成すると、MongoDBのデフォルトのデータベースパスはd:data(私のインストールディレクトリはDディスクの下)で、このファイルがなければ起動できません.
次のコマンドを使用してエラーを報告します.
D:\MongoDB\MongoDB\bin>mongo
MongoDB shell version v3.4.7
connecting to: mongodb://127.0.0.1:27017
2017-08-23T22:06:07.714+0800 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017 after 5000ms milliseconds, giving up.
2017-08-23T22:06:07.714+0800 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed
D:\MongoDB\MongoDB\bin>mongod
2017-08-23T07:08:09.045-0700 I CONTROL  [initandlisten] MongoDB starting : pid=14140 port=27017 dbpath=D:\data\db\ 64-bit host=�ز�����
2017-08-23T07:08:09.045-0700 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2017-08-23T07:08:09.046-0700 I CONTROL  [initandlisten] db version v3.4.7
2017-08-23T07:08:09.046-0700 I CONTROL  [initandlisten] git version: cf38c1b8a0a8dca4a11737581beafef4fe120bcd
2017-08-23T07:08:09.046-0700 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1u-fips  22 Sep 2016
2017-08-23T07:08:09.046-0700 I CONTROL  [initandlisten] allocator: tcmalloc
2017-08-23T07:08:09.046-0700 I CONTROL  [initandlisten] modules: none
2017-08-23T07:08:09.047-0700 I CONTROL  [initandlisten] build environment:
2017-08-23T07:08:09.048-0700 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
2017-08-23T07:08:09.049-0700 I CONTROL  [initandlisten]     distarch: x86_64
2017-08-23T07:08:09.049-0700 I CONTROL  [initandlisten]     target_arch: x86_64
2017-08-23T07:08:09.050-0700 I CONTROL  [initandlisten] options: {}
2017-08-23T07:08:09.051-0700 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory D:\data\db\ not found., terminating
2017-08-23T07:08:09.052-0700 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2017-08-23T07:08:09.053-0700 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2017-08-23T07:08:09.054-0700 I CONTROL  [initandlisten] now exiting
2017-08-23T07:08:09.056-0700 I CONTROL  [initandlisten] shutting down with code:100

なぜなら、MongoDBがデフォルトで探しているのはD:dataです.ただし、データベース・ファイルをdディスクの下に置くつもりはありません.次の方法でデータベース・パスを変更できます.
1、データベースの作成
mongod –dbpath d:\MongoDB\MongoDB\data

2、作成プロファイルファイルは任意の場所に置くことができ、私はMongDBルートディレクトリの下に置いた.ファイル名はmasterである.conf、ファイルを編集し、ファイルに次の内容を追加します.
dbpath=d:\MongoDB\MongoDB\data

次にMongodコマンドを実行します.
D:\MongoDB\MongoDB\bin>mongod --config d:\MongoDB\MongoDB\conf\master.conf
2017-08-23T07:12:29.633-0700 I CONTROL  [initandlisten] MongoDB starting : pid=10380 port=27017 dbpath=d:\MongoDB\MongoDB\data 64-bit host=�ز�����
2017-08-23T07:12:29.633-0700 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2017-08-23T07:12:29.636-0700 I CONTROL  [initandlisten] db version v3.4.7
2017-08-23T07:12:29.636-0700 I CONTROL  [initandlisten] git version: cf38c1b8a0a8dca4a11737581beafef4fe120bcd
2017-08-23T07:12:29.636-0700 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1u-fips  22 Sep 2016
2017-08-23T07:12:29.636-0700 I CONTROL  [initandlisten] allocator: tcmalloc
2017-08-23T07:12:29.636-0700 I CONTROL  [initandlisten] modules: none
2017-08-23T07:12:29.636-0700 I CONTROL  [initandlisten] build environment:
2017-08-23T07:12:29.636-0700 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
2017-08-23T07:12:29.636-0700 I CONTROL  [initandlisten]     distarch: x86_64
2017-08-23T07:12:29.636-0700 I CONTROL  [initandlisten]     target_arch: x86_64
2017-08-23T07:12:29.636-0700 I CONTROL  [initandlisten] options: { config: "d:\MongoDB\MongoDB\conf\master.conf", storage: { dbPath: "d:\MongoDB\MongoDB\data" } }
2017-08-23T07:12:29.641-0700 I -        [initandlisten] Detected data files in d:\MongoDB\MongoDB\data created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2017-08-23T07:12:29.641-0700 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=7639M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-08-23T07:12:30.255-0700 I CONTROL  [initandlisten]
2017-08-23T07:12:30.255-0700 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-08-23T07:12:30.255-0700 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-08-23T07:12:30.256-0700 I CONTROL  [initandlisten]
2017-08-23T22:12:30.661+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'd:/MongoDB/MongoDB/data/diagnostic.data'
2017-08-23T22:12:30.663+0800 I NETWORK  [thread1] waiting for connections on port 27017