For version 3.0.
Install
On VPS (ip: 123.56.18.18), download MongoDB binary package for Ubuntu 14.04 and extract:
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1404-3.0.3.tgz
cd /opt
tar zxf ~/mongodb-linux-x86_64-ubuntu1404-3.0.3.tgz
mkdir -p /data/db
Authentication Management
Start mongod without auth on VPS (ip: 123.56.18.18): mongod
;
Connect to server with mongo 123.56.18.18
;
Create system user administrator:
use admin
db.createUser(
{
user: "superuser",
pwd: "12345678",
roles: [ "root" ]
}
)
Create user in current database:
use products
db.createUser({user: "dba", pwd: "dba", roles: ["readWrite"]})
show users
Verify with db.getUsers()
.
Create a production config file mongo.conf:
net:
#bindIp: 10.251.212.248
port: 15515
systemLog:
destination: file
path: "mongo.log"
logAppend: true
security:
authorization: enabled
Stop and restart mongod with nohup mongod --config mongo.conf &
;
Connect to server as a database user: mongo 123.56.18.18:15515/products -u niufair -p nfsecret
.
You can show collections
, db.doc.insert()
, etc.
Start Meteor app with MONGO_URL="mongodb://niufair:nfsecret@123.56.18.18:15515/products" meteor
.
Connect to server as administrator: mongo 123.56.18.18:15515/admin -u leo -p leoisadmin
.
Use db.getUsers()
(or show users
) and db.dropUser("username")
to list and remove the user.
Create a new database under authentication
Say we want to create a new database named "bakdb":
mongo 123.56.18.18:15515/admin -u leo -p leoisadmin
use bakdb
db.createUser({user: "niufair", pwd: "nfsecret", roles: ["readWrite"]})
Verify: mongo -u niufair -p nfsecret 123.56.18.18:15515/bakdb
;
Ref:
Enable Authentication after Creating the User Administrator
Create an Administrative User with Unrestricted Access
http://stackoverflow.com/questions/4881208/how-to-put-username-password-in-mongodb
MMS
Connect mongodb server without authentication: mongo <ip>:<port>
;