Advertisement
Justman10000

Install MongoDB

Mar 10th, 2023 (edited)
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.22 KB | None | 0 0
  1. # To see all avaible os an versions, go to https://www.mongodb.com/try/download/community
  2. did=ubuntu2204
  3. version=8.0.3
  4.  
  5. wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-$did-$version.tgz
  6. gunzip mongodb-linux-x86_64-$did-$version.tgz
  7. tar xvf mongodb-linux-x86_64-$did-$version.tar
  8. mv mongodb-linux-x86_64-$did-$version /usr/local/mongodb
  9. rm -r /usr/local/mongodb/LICENSE-Community.txt /usr/local/mongodb/MPL-2 /usr/local/mongodb/THIRD-PARTY-NOTICES /usr/local/mongodb/README
  10. rm -r mongodb-linux-x86_64-$did-$version.tar
  11.  
  12. mkdir /usr/local/mongodb/db
  13. chmod -R 755 /usr/local/mongodb
  14. /usr/local/mongodb/bin/mongod --dbpath /usr/local/mongodb/db --bind_ip_all &
  15. echo $! > /usr/local/mongodb/pid
  16.  
  17. ln -fs /usr/local/mongodb/bin/* /usr/bin
  18.  
  19. # Connect
  20. mongosh --port 27017 -u USER_NAME -p 'PASSWORD' --authenticationDatabase 'admin'
  21.  
  22. # Create user
  23. ## Global perms
  24. db.createUser(
  25.   {
  26.     user: "USER_NAME",
  27.     pwd: "PASS",
  28.     roles: [ { role: "root", db: "admin" } ]
  29.   }
  30. )
  31. ## Local on a database
  32. db.createUser(
  33.   {
  34.     user: "USERNAME",
  35.     pwd: "PASS",
  36.     roles: [ { role: "dbOwner", db: "DB_NAME" } ]
  37.   }
  38. )
  39. # Delete user
  40. db.dropUser("USER_NAME")
  41.  
  42. # To shutdown
  43. kill $(cat /usr/local/mongodb/db/mongod.lock)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement