NoSQL database engine for document-oriented databases.
MongoDB is the solution for database requirements that stray away from traditional relational management: enter a NoSQL solution used by enterprise companies including eBay and Forbes. The document database allows users to start creating documents in your database without needing to establish a document structure, which allows users to edit on the fly and rapidly scale. Due to this flexibility in both data structure and management, MongoDB is often used as a single database solution for companies and organizations that have fluctuating DB needs.
Build your own flexible database with Linode’s MongoDB Marketplace App.
Deploying the MongoDB Marketplace App
The Linode Marketplace allows you to easily deploy software on a Linode using the Linode Cloud Manager.
- Log in to the Cloud Manager and select the Marketplace link from the left navigation menu. This displays the Linode Compute Create page with the Marketplace tab pre-selected.
- Under the Select App section, select the app you would like to deploy.
- Fill out all required Options for the selected app as well as any desired Advanced Options (which are optional). See the Configuration Options section for details.
- Complete the rest of the form as discussed within the Creating a Compute Instance.
- Click the Create Linode button. Once the Linode has provisioned and has fully powered on, wait for the software installation to complete. If the Linode is powered off or restarted before this time, the software installation will likely fail. To determine if the installation has completed, open the Linode’s Lish console and wait for the system login prompt to appear.
- Follow the instructions within the Getting Started After Deployment section.
Software installation should complete within 2-5 minutes after the Linode has finished provisioning.
Configuration Options
MongoDB Options
Here are the additional options available for this Marketplace App:
Field | Description |
---|---|
MongoDB admin user password | The Mongo admin user password. Required. |
MongoDB Version | Select the verison of MongoDB you’d like to install. |
Admin Email for the server | 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. |
Your Linode API Token | Your Linode API Token is needed to create DNS records. If this is provided along with the subdomain and domain fields, the installation attempts to create DNS records via the Linode API. If you don’t have a token, but you want the installation to create DNS records, you must create one before continuing. |
Subdomain | The subdomain you wish the installer to create a DNS record for during setup. The suggestion given is www . The subdomain should only be provided if you also provide a domain and API Token . |
Domain | The domain name where you wish to access your application. The installer creates a DNS record for this domain during setup if you provide this field along with your API Token . |
The limited sudo user to be created for the Linode | This is the limited user account to be created for the Linode. This account has sudo user privileges. |
The password for the limited sudo user | Set a password for the limited sudo user. The password must meet the complexity strength validation requirements for a strong password. This password can be used to perform any action on your server, similar to root, so make it long, complex, and unique. |
The SSH Public Key that will be used to access the Linode | If you wish to access SSH via Public Key (recommended) rather than by password, enter the public key here. |
Disable root access over SSH? | Select Yes to block the root account from logging into the server via SSH. Select No to allow the root account to login via SSH. |
General Options
For advice on filling out the remaining options on the Create a Linode form, see Creating a Compute Instance. Some options may be limited or have recommended values based on this Marketplace App:
- 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.
Getting Started after Deployment
Access the MongoDB Shell
After MongoDB has finished deploying, you can access and administer it directly from the console.
- Log in to your Compute Instance via SSH or Lish.
- 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.Theadmin
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
- As the
admin
user, create a new database to store regular user data for authentication. The following example calls this databaseuser-data
:use user-data
- Permissions for different databases are handled in separate
roles
objects. This example creates the user,example-user
, with read-only permissions for theuser-data
database and has read and write permissions for theexampleDB
database that we’ll create in the Manage Data and Collections section below.Create a new, non-administrative user to enter test data. Change bothexample-user
andpassword
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. - 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.
- Open the MongoDB shell using the
example-user
we created above:mongo -u example-user -p --authenticationDatabase user-data
- 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 thedb
command. - 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
. - 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
andb
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. - Insert the data into
exampleCollection
, using theinsert
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 })
- Confirm that the
exampleCollection
collection was properly created:show collections
The output will list all collections containing data within the current working database:exampleCollection
- View unfiltered data in the
exampleCollection
collection using thefind
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 andObjectId
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.Thefind
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 } }
The MongoDB Marketplace App was built by Linode. For support regarding app deployment, contact Linode Support via the information listed in the sidebar. For support regarding the tool or software itself, visit the MongoDB Community.