sql >> データベース >  >> NoSQL >> MongoDB

--authenticationDatabaseadminなしでmongodbインスタンスに接続します

    これは、ユーザーの資格情報が管理データベースに保存されており、ではないためです。 mongoシェルが接続するデフォルトのデータベース(テスト)。

    これは接続URLで変更できます:

    adminを使用 データベース:

    $ mongo localhost/admin --username user -p
    MongoDB shell version: 2.6.9
    Enter password:
    connecting to: localhost/admin
    replset:PRIMARY>
    

    特定のデータベースなし(test デフォルト):

    $ mongo localhost --username user -p
    MongoDB shell version: 2.6.9
    Enter password:
    connecting to: localhost
    2015-04-22T15:34:28.743+0100 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1260
    exception: login failed
    

    --authenticationDatabaseを使用 :

    $ mongo localhost --username user --authenticationDatabase admin -p
    MongoDB shell version: 2.6.9
    Enter password:
    connecting to: localhost
    replset:PRIMARY>
    

    --hostを使用することに注意してください データベース名が/の後の名前であるとは想定しません (スラッシュ:

    $ mongo --host localhost/admin --username user -p
    MongoDB shell version: 2.6.9
    Enter password:
    connecting to: localhost/admin:27017/test
    2015-04-22T15:37:40.703+0100 starting new replica set monitor for replica set localhost with seeds admin:27017
    2015-04-22T15:37:40.703+0100 [ReplicaSetMonitorWatcher] starting
    2015-04-22T15:37:40.920+0100 getaddrinfo("admin") failed: nodename nor servname provided, or not known
    2015-04-22T15:37:40.922+0100 warning: No primary detected for set localhost
    2015-04-22T15:37:40.922+0100 All nodes for set localhost are down. This has happened for 1 checks in a row. Polling will stop after 29 more failed checks
    2015-04-22T15:37:40.923+0100 Error: connect failed to replica set localhost/admin:27017 at src/mongo/shell/mongo.js:148
    exception: connect failed
    


    1. 流星のmongoデータベースにパスワードを設定します

    2. 内部構造の地理空間インデックス

    3. エラーが発生しました、エラー:サーバー127.0.0.1 shell / mongo.jsに接続できませんでした&macosxlionでmongodbを実行しようとしたとき

    4. クエリに存在しないフィールドを持つドキュメントを検索結果から除外するにはどうすればよいですか?