Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # To see all avaible os an versions, go to https://www.mongodb.com/try/download/community
- did=debian12
- version=8.0.6
- wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-$did-$version.tgz
- gunzip mongodb-linux-x86_64-$did-$version.tgz
- tar xvf mongodb-linux-x86_64-$did-$version.tar
- mv mongodb-linux-x86_64-$did-$version /usr/local/mongodb
- rm -r /usr/local/mongodb/LICENSE-Community.txt /usr/local/mongodb/MPL-2 /usr/local/mongodb/THIRD-PARTY-NOTICES /usr/local/mongodb/README
- rm -r mongodb-linux-x86_64-$did-$version.tar
- mkdir /usr/local/mongodb/db
- chmod -R 755 /usr/local/mongodb
- /usr/local/mongodb/bin/mongod --dbpath /usr/local/mongodb/db --bind_ip_all &
- echo $! > /usr/local/mongodb/pid
- ln -fs /usr/local/mongodb/bin/* /usr/bin
- reset
- read -p 'Username: ' username
- read -p 'Password: ' password
- [[ -z $username ]] || [[ -z $password ]] && exit
- # Connect
- mongosh --port 27017 -u $username -p $password --authenticationDatabase 'admin'
- # Create user
- ## Global perms
- use admin
- db.createUser(
- {
- user: $username,
- pwd: $password,
- roles: [ { role: "root", db: "admin" } ]
- }
- )
- ## Local on a database
- ### db.createUser(
- ### {
- ### user: "USERNAME",
- ### pwd: "PASS",
- ### roles: [ { role: "dbOwner", db: "DB_NAME" } ]
- ### }
- ### )
- # Delete user
- ## db.dropUser("USER_NAME")
- cat << EOF > .mongoshrc.js
- db.auth($username, $password)
- EOF
- # To shutdown
- ## kill $(cat /usr/local/mongodb/db/mongod.lock)
Advertisement
Add Comment
Please, Sign In to add comment