MongoDB

Discover our Public Cloud offer

Shared Hosting for Everyone, imagined by developers, for developers.

Discovering the Public Cloud

MongoDB is a document-oriented noSQL database program.

In our example, we use the SSH access and consider the following information:

  • Account name: foo
  • MongoDB directory: $HOME/mongodb/

[foo] must be replaced by your account name.

Installation

Downloading

foo@ssh:~$ mkdir mongodb
foo@ssh:~$ cd mongodb
foo@ssh:~/mongodb$ wget -O- https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian12-8.0.1.tgz | tar -xz --strip-components=1
foo@ssh:~/mongodb$ mkdir -p data log

Choose the package tgz and the platform Debian of the last version of the tarball.

Service launch

Create a service with following details:

  • Command: ./bin/mongod --dbpath ./data/ --logpath ./log/mongo.log --ipv6 --bind_ip_all --port=27017
  • Working directory: /home/[foo]/mongodb

Public Cloud users will need to point the service to a port between 8300 and 8499 instead of the default MongoDB port.

The address to connect to the MongoDB instance will be services-[foo].alwaysdata.net:[port].

Replace [port] by the chosen port in the command.

Firewall rule creation

Private Cloud users will need to open the port by creating a firewall rule if they want to access it from the external network:

TitleValue
ProtocolUDP/TCP
TypeACCEPT
DirectionInput
Hosts<specify nothing>
Ports27017
IP versionIPv4/IPv6

Downloading and installing utilities

  • mongosh - choose the package tgz and the platform Linux x64 of the last version.
foo@ssh:~/mongodb$ wget -O- https://downloads.mongodb.com/compass/mongosh-2.3.2-linux-x64.tgz | tar -xz --strip-components=0
foo@ssh:~/mongodb$ mv mongosh-2.3.2-linux-x64/bin/* bin/
foo@ssh:~/mongodb$ rm -rf mongosh-2.3.2-linux-x64
  • cli - choose the package tgz and the platform Debian 12.0 x86-64 of the last version.
foo@ssh:~/mongodb$ wget -O- https://fastdl.mongodb.org/tools/db/mongodb-database-tools-debian12-x86_64-100.10.0.tgz | tar -xz --strip-components=0
foo@ssh:~/mongodb$ mv mongodb-database-tools-debian12-x86_64-100.10.0/bin/* bin/
foo@ssh:~/mongodb$ rm -rf mongodb-database-tools-debian12-x86_64-100.10.0

All executables will then be located in $HOME/mongodb/bin.

Authentication

Here, we will create the admin user following their documentation.

foo@ssh: ~/mongodb$ ./bin/mongosh services-[foo].alwaysdata.net:[port]
Current Mongosh Log ID:	6707c8c098d8f59e6efe6910
Connecting to:		mongodb://services-[foo].alwaysdata.net:[port]/?directConnection=true&appName=mongosh+2.3.2
Using MongoDB:		8.0.1
Using Mongosh:		2.3.2

------

test> use admin
switched to db admin
admin> db.createUser(
...   {
...     user: "admin",
...     pwd: "mysuperpassword",
...     roles: [
...       { role: "userAdminAnyDatabase", db: "admin" },
...       { role: "readWriteAnyDatabase", db: "admin" }
...     ]
...   }
... )
{ ok: 1 }
admin>

Replace mysuperpassword by the password of your choice.

You can then add the --auth option to the command for the service.