1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

mongo-express : Web-based MongoDB admin interface

Last updated at Posted at 2016-01-08

What's this?

mongo-express で MongoDB に Web アクセス、ついでに Openstack Ceilometer の MongoDB を覗く。

Procedure

Install node.js

$ wget https://nodejs.org/dist/v4.1.2/node-v4.1.2.tar.gz
$ tar -zxvf node-v4.1.2.tar.gz
$ cd node-v4.1.2/
$ ./configure --prefix=/usr/local
$ make
$ sudo make install

$ /usr/local/bin/node -v
v4.1.2

$ /usr/local/bin/npm -v
2.14.4

npm init

プロジェクトのためのディレクトリ作成、移動

# mkdir mongo-express
# cd mongo-express/

このディレクトリ下は npmが管理する宣言

# npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sane defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
name: (mongo-express)                   <== INPUT
version: (0.0.0)                        <
description: MongoDB-Express            <
entry point: (index.js)                 <
test command:                           <
git repository:                         <
keywords:                               <
author:                                 <
license: (BSD)                          <
About to write to /root/mongo-express/package.json:

{
  "name": "mongo-express",
  "version": "0.0.0",
  "description": "MongoDB-Express",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "BSD"
}


Is this ok? (yes)

json file が作成される

# cat package.json
{
  "name": "mongodb-express",
  "version": "1.0.0",
  "description": "MongoDB-Express",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

Install mongo-express

# npm install mongo-express --save
~~ 省略 ~~
mongo-express@0.23.2 node_modules/mongo-express
├── async@1.4.2
├── basic-auth-connect@1.0.0
├── consolidate@0.12.1
├── underscore@1.8.3
├── cookie-parser@1.4.0 (cookie-signature@1.0.6, cookie@0.2.2)
├── serve-favicon@2.3.0 (etag@1.7.0, fresh@0.3.0, ms@0.7.1, parseurl@1.3.0)
├── morgan@1.6.1 (on-headers@1.0.1, basic-auth@1.0.3, depd@1.0.1, on-finished@2.3.0, debug@2.2.0)
├── method-override@2.3.5 (vary@1.0.1, methods@1.1.1, parseurl@1.3.0, debug@2.2.0)
├── express-session@1.11.3 (cookie@0.1.3, cookie-signature@1.0.6, utils-merge@1.0.0, on-headers@1.0.1, parseurl@1.3.0, depd@1.0.1, crc@3.3.0, uid-safe@2.0.0, debug@2.2.0)
├── errorhandler@1.4.2 (escape-html@1.0.2, accepts@1.2.13)
├── express@4.13.3 (escape-html@1.0.2, cookie@0.1.3, cookie-signature@1.0.6, utils-merge@1.0.0, content-type@1.0.1, methods@1.1.1, vary@1.0.1, etag@1.7.0, fresh@0.3.0, merge-descriptors@1.0.0, array-flatten@1.1.1, parseurl@1.3.0, serve-static@1.10.0, range-parser@1.0.2, content-disposition@0.5.0, path-to-regexp@0.1.7, depd@1.0.1, qs@4.0.0, on-finished@2.3.0, finalhandler@0.4.0, debug@2.2.0, proxy-addr@1.0.8, type-is@1.6.9, accepts@1.2.13, send@0.13.0)
├── body-parser@1.14.0 (bytes@2.1.0, content-type@1.0.1, depd@1.1.0, qs@5.1.0, on-finished@2.3.0, debug@2.2.0, http-errors@1.3.1, iconv-lite@0.4.11, type-is@1.6.9, raw-body@2.1.4)
├── swig@1.4.2 (optimist@0.6.1, uglify-js@2.4.24)
└── mongodb@2.0.43 (es6-promise@2.1.1, readable-stream@1.0.31, mongodb-core@1.2.12)


# ll node_modules/mongo-express/
total 72K
-rw-r--r--  1 root root  449 Sep 28 23:29 app.js
-rw-r--r--  1 root root 2578 Sep 28 23:01 bson.js
-rw-r--r--  1 root root 3275 Sep 28 23:17 config.default.js
-rw-r--r--  1 root root 4421 Oct  2 07:53 db.js
-rw-r--r--  1 root root  144 Sep 28 12:50 Dockerfile
-rw-r--r--  1 root root 1020 Sep 28 23:17 filters.js
-rw-r--r--  1 root root 2093 Sep 26 01:26 HISTORY.md
-rw-r--r--  1 root root 7785 Sep 28 23:12 json.js
-rw-r--r--  1 root root  621 Sep 28 23:12 middleware.js
drwxr-xr-x 17 root root 4096 Oct  8 17:36 node_modules/
-rw-r--r--  1 root root 1808 Oct  8 17:36 package.json
drwxr-xr-x  5 root root   55 Oct  8 17:36 public/
-rw-r--r--  1 root root 7179 Sep 29 08:17 README.md
-rw-r--r--  1 root root 5738 Sep 29 12:36 router.js
drwxr-xr-x  2 root root   77 Oct  8 17:36 routes/
drwxr-xr-x  2 root root   37 Oct  8 17:36 test/
-rw-r--r--  1 root root  449 Sep 28 22:58 utils.js
drwxr-xr-x  2 root root  103 Oct  8 17:36 views/

Configure

# pwd
/root/mongo-express/node_modules/mongo-express
# cp config.default.js config.js
# vi config.js

# diff config.default.js config.js
11c11
<     server: process.env.ME_CONFIG_MONGODB_SERVER || 'localhost',
---
>     server: process.env.ME_CONFIG_MONGODB_SERVER || 'xxx.xxx.xxx.xxx',  <== MongoDB Server IP
31,33c31,33
<         database: 'test',                                               <== DELETE
<         username: 'user',                                               <
<         password: 'pass'                                                <
---                                                                       <
>         database: '',                                                   <
>         username: '',                                                   <
>         password: ''                                                    <
43,44c43,44
<     adminUsername: '',                                                  <== ADD: MongoDB ID/PW
<     adminPassword: '',                                                  <
---                                                                       <
>     adminUsername: 'admin',                                             <
>     adminPassword: '*****',                                             <
65c65
<     password: process.env.ME_CONFIG_BASICAUTH_PASSWORD || 'pass'        <== UPDATE: Basic Auth PW
---                                                                       <
>     password: process.env.ME_CONFIG_BASICAUTH_PASSWORD || '*****'       <

Run

# pwd
/root/mongo-express/node_modules/mongo-express

# node app.js
Mongo Express server listening on port 8081 at 0.0.0.0
Database connected!
Admin Database connected
GET / 200 104.510 ms - 4622
GET /stylesheets/bootstrap.css 200 7.646 ms - 98983
GET /stylesheets/bootstrap-responsive.min.css 200 9.788 ms - 10518
GET /stylesheets/style.css 200 9.769 ms - 117
GET /javascripts/bootstrap.min.js 200 3.192 ms - 22323
GET /javascripts/jquery-1.7.2.min.js 200 3.032 ms - 94840
GET /images/glyphicons-halflings.png 200 1.519 ms - 13826
GET /db/admin 200 49.691 ms - 4554
~~ 省略 ~~
# ^C

Shell にして常時起動

# cat mongo-express.sh
#!/bin/sh

NODE="/usr/local/bin/node"
APP_JS="/root/mongo-express/node_modules/mongo-express/app.js"

nohup ${NODE} ${APP_JS} &

exit

GUI

mongo_express01.png

mongo_express02.png

mongo_express03.png

Reference

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?