miércoles, 27 de febrero de 2019

Setup MongoDB and Compass on Arch Linux

Hey, my second post in English, Hooray! I wanted to take note in case I need to do this again in another computer, hehehe, so here it is... How to setup MongoDB and Compass on Arch Linux, on a development computer:
  • First, we proceed to download and install MongoDB and MongoDB Compass. We can do this via a package manager like Pamac, or via the command line using yaourt or git/curl + makepkg. This is because these packages are not part of the official Arch repositories, but are available as part of the Arch User Repository (AUR). To download and install these packages via yaourt, we can execute the next command:
    $ yaourt -S mongodb-bin mongodb-compass-community
    With this command we will install the binaries for a recent version of MongoDB, and the MongoDB Compass Community Version.
  • Then, we create the default folder for Mongo DB databases, as root:
    # mkdir -p /data/db 
  • After that, in order to be able to start the Mongo daemon service as a normal user, I suggest to create a user group, so we will be able to add to it all the users we want to give access to Mongo and other developer tools. For example, let's create the group developers:
    # groupadd developers
  • Add the required users to the group:
    # gpasswd -a <user> developers
  • Set the group as owner of the Mongo data folder:
    chown -R :developers /data/db/
  • Change permissions of the folder so the user that was just added to the group will be able to write in it:
    # chmod -R g+w /data/db/
  • Re-login or as <user> log your terminal in to the newly created group:
    $ newgrp developers
  • At this point, you will be able to start MongoDB with the current user:
    $ mongod
    If everything is OK, you will see a event log in the terminal without any errors, and messages indicating that MongoDB has created its default collections, and that it is waiting for connections on port 27017, which is the default one.
  • Finally, you can run:
    $ mongodb-compass-community
    To open Compass, and use the default parameters to connect to the local instance of MongoDB.
Happy coding!
Con la tecnología de Blogger.