MongoDB

Create Username MongoDB

Login ke Mongo shell, kemudian gunakan command:

use admin


db.createUser(

{

user: "YOUR_USERNAME",

pwd: "YOUR_PASSWORD",

roles: [ "root" ]

}

)

tambahkan line berikut di /etc/mongod.conf :

security:

authorization: enabled

Restart mongodb:

sudo service mongod restart

Backup MongoDB Atlas menggunakan mongodump

sudo mongodump -d $YOUR_DB -u $YOUR_USERNAME -p "$YOUR_PASSWORD" \

-o . --authenticationDatabase admin --ssl --port 27017 \

-h "your-cluster-shard-00-02.zwvf2.cloud.mongodb.net,your-cluster-shard-00-01.zwvf2.cloud.mongodb.net,your-cluster-shard-00-00.zwvf2.cloud.mongodb.net"

Restore Mongo di localhost yang sudah terdapat user authenfication

sudo mongorestore -d $YOUR_DATABASE --drop /TO/YOUR/BACKUP/PATH -u $YOUR_YOUSERNAME -p "$YOUR_PASSWORD" \

--authenticationDatabase admin