cari

Rumah  >  Soal Jawab  >  teks badan

mongodb连接出错

明明db.auth返回1,可是mongo -u admin -p就是失败,为啥呢?

andyliwr@andyliwrPC:~/文档/xiaodiFTP/nodejs/xiaodiTodoList$ mongo
MongoDB shell version: 2.6.10
connecting to: test
> use admin
switched to db admin
> db.auth("admin", "123456")
1
> db.auth("admin", "1234535")
Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 }
0
> exit
bye
andyliwr@andyliwrPC:~/文档/xiaodiFTP/nodejs/xiaodiTodoList$ mongo -u admin -p
MongoDB shell version: 2.6.10
Enter password: 
connecting to: test
2016-07-31T22:41:33.520+0800 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1287
exception: login failed
阿神阿神2811 hari yang lalu654

membalas semua(2)saya akan balas

  • 迷茫

    迷茫2017-05-02 09:22:59

    Pengguna anda berada dalam pangkalan data admin dan pangkalan data sambungan lalai ialah test Anda harus menentukan pangkalan data sebagai mongo apabila menggunakan admin untuk menyambung, supaya ia boleh. selesai. Pengesahan yang betul:

    mongo -u admin -p admin

    balas
    0
  • PHPz

    PHPz2017-05-02 09:22:59

    mongo localhost/admin -u admin -p
    // or
    mongo -u admin -p --authenticationDatabase admin
    

    adalah untuk menentukan penggunaan admin pengguna dalam perpustakaan ini untuk pengesahan. Jika anda menghadapi masalah mencari dokumentasi, sila lihat --help. Versi pada mesin saya ialah 3.2, yang mungkin berbeza sedikit daripada anda pada 2.6.

    $ mongo --help
    MongoDB shell version: 3.2.6
    usage: mongo [options] [db address] [file names (ending in .js)]
    db address can be:
      foo                   foo database on local machine
      192.169.0.5/foo       foo database on 192.168.0.5 machine
      192.169.0.5:9999/foo  foo database on 192.168.0.5 machine on port 9999
    Options:
      --shell                             run the shell after executing files
      --nodb                              don't connect to mongod on startup - no
                                          'db address' arg expected
      --norc                              will not run the ".mongorc.js" file on
                                          start up
      --quiet                             be less chatty
      --port arg                          port to connect to
      --host arg                          server to connect to
      --eval arg                          evaluate javascript
      -h [ --help ]                       show this usage information
      --version                           show version information
      --verbose                           increase verbosity
      --ipv6                              enable IPv6 support (disabled by default)
      --disableJavaScriptJIT              disable the Javascript Just In Time
                                          compiler
      --enableJavaScriptProtection        disable automatic JavaScript function
                                          marshalling
      --ssl                               use SSL for all connections
      --sslCAFile arg                     Certificate Authority file for SSL
      --sslPEMKeyFile arg                 PEM certificate/key file for SSL
      --sslPEMKeyPassword arg             password for key in PEM file for SSL
      --sslCRLFile arg                    Certificate Revocation List file for SSL
      --sslAllowInvalidHostnames          allow connections to servers with
                                          non-matching hostnames
      --sslAllowInvalidCertificates       allow connections to servers with invalid
                                          certificates
      --sslFIPSMode                       activate FIPS 140-2 mode at startup
    
    Authentication Options:
      -u [ --username ] arg               username for authentication
      -p [ --password ] arg               password for authentication
      --authenticationDatabase arg        user source (defaults to dbname)
      --authenticationMechanism arg       authentication mechanism
      --gssapiServiceName arg (=mongodb)  Service name to use when authenticating
                                          using GSSAPI/Kerberos
      --gssapiHostName arg                Remote host name to use for purpose of
                                          GSSAPI/Kerberos authentication
    

    balas
    0
  • Batalbalas