2015-11-27 92 views
1

這裏是我的mongo-express配置,當我登錄http://192.168.1.104:8081時,它只顯示admin db,我想要它顯示所有db如何讓mongo-express顯示所有db?

'use strict'; 

var url = require('url'); 

if (typeof process.env.MONGODB_PORT === 'string') { 
    var mongoConnection = url.parse(process.env.MONGODB_PORT); 
    process.env.ME_CONFIG_MONGODB_SERVER = mongoConnection.hostname; 
    process.env.ME_CONFIG_MONGODB_PORT = mongoConnection.port; 
} 

module.exports = { 
    mongodb: { 
    server: process.env.ME_CONFIG_MONGODB_SERVER || 'localhost', 
    port: process.env.ME_CONFIG_MONGODB_PORT || 27017, 

    //autoReconnect: automatically reconnect if connection is lost 
    autoReconnect: true, 
    //poolSize: size of connection pool (number of connections to use) 
    poolSize: 4, 
    //set admin to true if you want to turn on admin features 
    //if admin is true, the auth list below will be ignored 
    //if admin is true, you will need to enter an admin username/password below (if it is needed) 
    admin: true, 


    // >>>> If you are using regular accounts, fill out auth details in the section below 
    // >>>> If you have admin auth, leave this section empty and skip to the next section 
    auth: [ 
     /* 
     * Add the the name, the username, and the password of the databases you want to connect to 
     * Add as many databases as you want! 
     { 
     database: 'test', 
     username: 'user', 
     password: 'pass' 
     } 
     */ 
     ], 


    // >>>> If you are using an admin mongodb account, or no admin account exists, fill out section below 
    // >>>> Using an admin account allows you to view and edit all databases, and view stats 

    //leave username and password empty if no admin account exists 
    adminUsername: process.env.ME_CONFIG_MONGODB_ADMINUSERNAME || '', 
    adminPassword: process.env.ME_CONFIG_MONGODB_ADMINPASSWORD || '', 
    //whitelist: hide all databases except the ones in this list (empty list for no whitelist) 
    whitelist: [], 
    //blacklist: hide databases listed in the blacklist (empty list for no blacklist) 
    blacklist: [] 
    }, 

    site: { 
    host: '192.168.1.104', 
    port: 8081, 
    cookieSecret: process.env.ME_CONFIG_SITE_COOKIESECRET || 'cookiesecret', 
    sessionSecret: process.env.ME_CONFIG_SITE_SESSIONSECRET || 'sessionsecret', 
    cookieKeyName: 'mongo-express', 
    sslEnabled: process.env.ME_CONFIG_SITE_SSL_ENABLED || false, 
    sslCert: process.env.ME_CONFIG_SITE_SSL_CRT_PATH || '', 
    sslKey: process.env.ME_CONFIG_SITE_SSL_KEY_PATH || '' 
    }, 

    //set useBasicAuth to true if you want to authehticate mongo-express loggins 
    //if admin is false, the basicAuthInfo list below will be ignored 
    //this will be true unless ME_CONFIG_BASICAUTH_USERNAME is set and is the empty string 
    useBasicAuth: process.env.ME_CONFIG_BASICAUTH_USERNAME !== '', 

    basicAuth: { 
    username: process.env.ME_CONFIG_BASICAUTH_USERNAME || 'root', 
    password: process.env.ME_CONFIG_BASICAUTH_PASSWORD || 'password' 
    }, 

    options: { 
    //documentsPerPage: how many documents you want to see at once in collection view 
    documentsPerPage: 10, 
    //editorTheme: Name of the theme you want to use for displaying documents 
    //See http://codemirror.net/demo/theme.html for all examples 
    editorTheme: process.env.ME_CONFIG_OPTIONS_EDITORTHEME || 'rubyblue', 

    //The options below aren't being used yet 

    //cmdType: the type of command line you want mongo express to run 
    //values: eval, subprocess 
    // eval - uses db.eval. commands block, so only use this if you have to 
    // subprocess - spawns a mongo command line as a subprocess and pipes output to mongo express 
    cmdType: 'eval', 
    //subprocessTimeout: number of seconds of non-interaction before a subprocess is shut down 
    subprocessTimeout: 300, 
    //readOnly: if readOnly is true, components of writing are not visible. 
    readOnly: false 
    }, 

    // Specify the default keyname that should be picked from a document to display in collections list. 
    // Keynames can be specified for every database and collection. 
    // If no keyname is specified, it defalts to '_id', which is a mandatory feild. 
    // For Example : 
    // defaultKeyNames{ 
    // "world_db":{ //Database Name 
    //  "continent":"cont_name", // collection:feild 
    //  "country":"country_name", 
    //  "city":"name" 
    // } 
    // } 
    defaultKeyNames: { 

    } 
}; 

備註:以上配置 , BASICAUTH:{ 用戶名:我之前

use admin 

db.createUser(
{ 
user: "root", 
pwd: "password", 
roles: [ "root" ] 
} 
) 

配置文件已經運行此命令process.env.ME_CONFIG_BASICAUTH_USERNAME || 'root', password:process.env.ME_CONFIG_BASICAUTH_PASSWORD || '密碼' },

我改變了用戶名,密碼分別爲root和密碼,當我訪問http://192.168.1.104:8081時,我需要在http auth提示符下輸入root和密碼,以便進入mongo-express Web面板。

回答

4

這是我在StackOverflow上的第一個答案,但希望它有幫助。

您的案例中的問題似乎是在config.js中定義的數據庫身份驗證。 您需要通過「身份驗證」部分傳遞數據庫憑據,而不是通過「basicAuth」。 此外,一旦你糾正config.js文件,啓動蒙戈快車與-a開關,即 - >cd YOUR_PATH/node_modules/mongo-express/ && node app.js -a

更正config.js的部分:

admin: true, 


// >>>> If you are using regular accounts, fill out auth details in the section below 
// >>>> If you have admin auth, leave this section empty and skip to the next section 
auth: [ 
    /* 
    * Add the the name, the username, and the password of the databases you want to connect to 
    * Add as many databases as you want! 
    { 
    database: 'test', 
    username: 'user', 
    password: 'pass' 
    } 
    */ 
    ], 


// >>>> If you are using an admin mongodb account, or no admin account exists, fill out section below 
// >>>> Using an admin account allows you to view and edit all databases, and view stats 

//leave username and password empty if no admin account exists 
adminUsername: process.env.ME_CONFIG_MONGODB_ADMINUSERNAME || 'root', 
adminPassword: process.env.ME_CONFIG_MONGODB_ADMINPASSWORD || 'password',