Guides - Deploying MongoDB through the Linode Marketplace

Quickly deploy a Compute Instance with many various software applications pre-installed and ready to use.

Create a Linode account to try this guide with a $100 credit.
This credit will be applied to any valid services used during your first 60 days.

MongoDB is a database engine that provides access to non-relational, document-oriented databases. It is part of the growing NoSQL movement, along with databases like Redis and Cassandra (although there are vast differences among the many non-relational databases).

MongoDB seeks to provide an alternative to traditional relational database management systems (RDBMS). In addition to its schema-free design and scalable architecture, MongoDB provides a JSON output and specialized, language-specific bindings that make it particularly attractive for use in custom application development and rapid prototyping. MongoDB has been used in a number of large scale production deployments and is currently one of the most popular database engines across all systems.

Deploying a Marketplace App

The Linode Marketplace allows you to easily deploy software on a Compute Instance using the Cloud Manager. See Get Started with Marketplace Apps for complete steps.

  1. Log in to the Cloud Manager and select the Marketplace link from the left navigation menu. This displays the Linode Create page with the Marketplace tab pre-selected.

  2. Under the Select App section, select the app you would like to deploy.

  3. Complete the form by following the steps and advice within the Creating a Compute Instance guide. Depending on the Marketplace App you selected, there may be additional configuration options available. See the Configuration Options section below for compatible distributions, recommended plans, and any additional configuration options available for this Marketplace App.

  4. Click the Create Linode button. Once the Compute Instance has been provisioned and has fully powered on, wait for the software installation to complete. If the instance is powered off or restarted before this time, the software installation will likely fail.

To verify that the app has been fully installed, see Get Started with Marketplace Apps > Verify Installation. Once installed, follow the instructions within the Getting Started After Deployment section to access the application and start using it.

Note
Estimated deployment time: MongoDB should be fully installed within 2-5 minutes after the Compute Instance has finished provisioning.

Configuration Options

  • Supported distributions: Debian 11, Ubuntu 20.04 LTS
  • Recommended minimum plan: All plan types and sizes can be used, though consider using a High Memory Compute Instance for larger databases in a production environment.

MongoDB Options

  • MongoDB admin user password (required): The Mongo admin user password.
  • MongoDB Version (required): Select the verison of MongoDB you’d like to install.

Limited User (Optional)

You can optionally fill out the following fields to automatically create a limited user for your new Compute Instance. This is recommended for most deployments as an additional security measure. This account will be assigned to the sudo group, which provides elevated permission when running commands with the sudo prefix.

  • Limited sudo user: Enter your preferred username for the limited user.
  • Password for the limited user: Enter a strong password for the new user.
  • SSH public key for the limited user: If you wish to login as the limited user through public key authentication (without entering a password), enter your public key here. See Creating an SSH Key Pair and Configuring Public Key Authentication on a Server for instructions on generating a key pair.
  • Disable root access over SSH: To block the root user from logging in over SSH, select Yes (recommended). You can still switch to the root user once logged in and you can also log in as root through Lish.

Custom Domain (Optional)

If you wish to access your application using a custom domain, fill out the following fields.

  • Linode API Token: If you wish to use the Linode’s DNS Manager to manage DNS records for your custom domain, create a Linode API Personal Access Token on your account with Read/Write access to Domains. If this is provided along with the subdomain and domain fields (outlined below), the installation attempts to create DNS records via the Linode API. See Get an API Access Token. If you do not provide this field, you need to manually configure your DNS records through your DNS provider and point them to the IP address of the new instance.
  • Subdomain: The subdomain you wish to use, such as www for www.example.com.
  • Domain: The domain name you wish to use, such as example.com.
  • Email address for soa record: The start of authority (SOA) email address for this server. This email address will be added to the SOA record for the domain. This is a required field if you want the installer to create DNS records.

Getting Started after Deployment

Access the MongoDB Shell

After MongoDB has finished deploying, you can access and administer it directly from the console.

  1. Log in to your Compute Instance via SSH or Lish.

  2. Launch the mongo shell by running the following command. When prompted, enter the admin user password you set when creating this instance.

    mongo -u admin -p --authenticationDatabase admin
    

    The -u, -p, and --authenticationDatabase options in the above command are required in order to authenticate connections to the shell. Without authentication, the MongoDB shell can be accessed but will not allow connections to databases.

    The admin user is purely administrative based on the roles specified. It is defined as an administrator of users for all databases, but does not have any database permissions itself. You may use it to create additional users and define their roles. If you are using multiple applications with MongoDB, set up different users with custom permissions for their corresponding databases.

Create a User Table

  1. As the admin user, create a new database to store regular user data for authentication. The following example calls this database user-data:

    use user-data
    
  2. Permissions for different databases are handled in separate roles objects. This example creates the user, example-user, with read-only permissions for the user-data database and has read and write permissions for the exampleDB database that we’ll create in the Manage Data and Collections section below.

    Create a new, non-administrative user to enter test data. Change both example-user and password to something relevant and secure:

    db.createUser({user: "example-user", pwd: "password", roles:[{role: "read", db: "user-data"}, {role:"readWrite", db: "exampleDB"}]})
    

    To create additional users, repeat this step as the administrative user, creating new usernames, passwords and roles by substituting the appropriate values.

  3. Exit the mongo shell:

    quit()
    

For more information on access control and user management, as well as other tips on securing your databases, refer to the MongoDB Security Documentation.

Manage Data and Collections

Much of MongoDB’s popularity comes from its ease of integration. Interactions with databases are done via JavaScript methods, but drivers for other languages are available. This section will demonstrate a few basic features, but we encourage you to do further research based on your specific use case.

  1. Open the MongoDB shell using the example-user we created above:

    mongo -u example-user -p --authenticationDatabase user-data
    
  2. Create a new database. This example calls it exampleDB:

    use exampleDB
    

    Make sure that this database name corresponds with the one for which the user has read and write permissions (we added these permissions in the previous section).

    To show the name of the current working database, run the db command.

  3. Create a new collection called exampleCollection:

    db.createCollection("exampleCollection", {capped: false})
    

    If you’re not familiar with MongoDB terminology, you can think of a collection as analogous to a table in a relational database management system. For more information on creating new collections, see the MongoDB documentation on the db.createCollection() method.

    Note
    Collection names should not include certain punctuation such as hyphens. However, exceptions may not be raised until you attempt to use or modify the collection. For more information, refer to MongoDB’s naming restrictions.
  4. Create sample data for entry into the test database. MongoDB accepts input as documents in the form of JSON objects such as those below. The a and b variables are used to simplify entry; objects can be inserted directly via functions as well.

    var a = { name : "John Doe",  attributes: { age : 30, address : "123 Main St", phone : 8675309 }}
    var b = { name : "Jane Doe",  attributes: { age : 29, address : "321 Main Rd", favorites : { food : "Spaghetti", animal : "Dog" } }}
    

    Note that documents inserted into a collection need not have the same schema, which is one of many benefits of using a NoSQL database.

  5. Insert the data into exampleCollection, using the insert method:

    db.exampleCollection.insert(a)
    db.exampleCollection.insert(b)
    

    The output for each of these operations will show the number of objects successfully written to the current working database:

    WriteResult({ "nInserted" : 1 })
  6. Confirm that the exampleCollection collection was properly created:

    show collections
    

    The output will list all collections containing data within the current working database:

    exampleCollection
  7. View unfiltered data in the exampleCollection collection using the find method. This returns up to the first 20 documents in a collection, if a query is not passed:

    db.exampleCollection.find()
    

    The output will resemble the following:

    { "_id" : ObjectId("5e68d4618bd4ea23cc3f5e96"), "name" : "John Doe", "attributes" : { "age" : 30, "address" : "123 Main St", "phone" : 8675309 } }
    { "_id" : ObjectId("5e68d4628bd4ea23cc3f5e97"), "name" : "Jane Doe", "attributes" : { "age" : 29, "address" : "321 Main Rd", "favorites" : { "food" : "Spaghetti", "animal" : "Dog" } } }

    You may notice the objects we entered are preceded by _id keys and ObjectId values. These are unique indexes generated by MongoDB when an _id value is not explicitly defined. ObjectId values can be used as primary keys when entering queries, although for ease of use, you may wish to create your own index as you would with any other database system.

    The find method can also be used to search for a specific document or field by entering a search term parameter (in the form of an object) rather than leaving it empty. For example:

    db.exampleCollection.find({"name" : "John Doe"})
    

    Running the command above returns a list of documents containing the {"name" : "John Doe"} object:

    { "_id" : ObjectId("5e68d4618bd4ea23cc3f5e96"), "name" : "John Doe", "attributes" : { "age" : 30, "address" : "123 Main St", "phone" : 8675309 } }

Next Steps

Note
Currently, Linode does not manage software and systems updates for Marketplace Apps. It is up to the user to perform routine maintenance on software deployed in this fashion.

For more on MongoDB, checkout the following guides:

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

This page was originally published on


Your Feedback Is Important

Let us know if this guide made it easy to get the answer you needed.