MongoDB is a cross-platform, document-oriented database that provides high performance, high availability, and easy scalability. MongoDB works on the concepts of collections and documents. MongoDB maintainers have not yet released official Ubuntu 16.04 MongoDB packages. This article explains "How to install Mongo DB on Ubuntu and start the MongoDB service at boot"
Add MongoDB repository
MongoDB is usually included in the Ubuntu package repository. However, legitimate MongoDB repositories provide the latest version changes in an approved manner.
To perform this process we first have to import the keys for a legitimate MongoDB repository using the following command -
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
The example output should look like this –
Executing: /tmp/tmp.Qe1RFZgUh2/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 gpg: requesting key EA312927 from hkp server keyserver.ubuntu.com gpg: key EA312927: public key "MongoDB 3.2 Release Signing Key <packaging@mongodb.com>" imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1)
To add MongoDB repository, use the following command -
$ sudo echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
Now we need to update the package list using the following command -
$ sudo apt-get update
Install and verify MongoDB
To install MongoDB, use The following command –
$ sudo apt-get install -y --allow-unauthenticated mongodb-org
The sample output should look like this –
Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: apport-hooks-elementary contractor javascript-common libgda-5.0-4 libgda-5.0-common libgranite-common libgranite3 libgsignon-glib1 libindicate5 libjs-jquery libnoise-core0 libtagc0 Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools The following NEW packages will be installed: mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools 0 upgraded, 5 newly installed, 0 to remove and 168 not upgraded. Need to get 47.4 MB of archives. After this operation, 218 MB of additional disk space will be used. Get:1 http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2/multiverse amd64 mongodb-org-shell amd64 3.2.6 [5,257 kB] Get:2 http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2/multiverse amd64 mongodb-org-server amd64 3.2.6 [9,541 kB] Get:3 http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2/multiverse amd64 mongodb-org-mongos amd64 3.2.6 [4,337 kB] ...................................................................................
In order to properly start MongoDB as a service on Ubuntu 16.04, we also need to create a unit file that describes the service. Unit files tell the system a way to manage resources. The most common unit type is a service, which determines how to start or stop the service.
Create a configuration file called mongodb.service to set up the unit file as shown below –
$ sudo nano /etc/systemd/system/mongodb.service
Paste the following code –
[Unit] Description=High-performance, schema-free document-oriented database After=network.target [Service] User=mongodb ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf [Install] WantedBy=multi-user.target
Now use systemctl Start the newly created service as shown below -
$ sudo systemctl start mongodb
It usually returns no output. Now we need to check if the service has started normally. In order to perform this process, use the following command -
$ sudo systemctl status mongodb
The sample output should be like this –
mongodb.service - High-performance, schema-free document-oriented database Loaded: loaded (/etc/systemd/system/mongodb.service; disabled; vendor preset: Active: active (running) since Fri 2016-05-13 10:33:52 IST; 1min 48s ago Main PID: 7078 (mongod) Tasks: 16 (limit: 512) CGroup: /system.slice/mongodb.service └─7078 /usr/bin/mongod --quiet --config /etc/mongod.conf May 13 10:33:52 linux systemd[1]: Started High-performance, schema-free document lines 1-9/9 (END)
To enable the process of automatically starting MongoDB when the system starts, use the following command -
$ sudo systemctl enable mongodb
The sample output should be like this –
Created symlink from /etc/systemd/system/multi-user.target.wants/mongodb.service to /etc/systemd/system/mongodb.service.
After reading this article, you will be able to understand – How to install MongoDB on Ubuntu 16.04. In the following articles, we will come up with more Linux-based tips and tricks. continue reading!
The above is the detailed content of How to install MongoDB on Ubuntu 16.04. For more information, please follow other related articles on the PHP Chinese website!

MongoDB's scalability and performance considerations include horizontal scaling, vertical scaling, and performance optimization. 1. Horizontal expansion is achieved through sharding technology to improve system capacity. 2. Vertical expansion improves performance by increasing hardware resources. 3. Performance optimization is achieved through rational design of indexes and optimized query strategies.

MongoDB is a NoSQL database because of its flexibility and scalability are very important in modern data management. It uses document storage, is suitable for processing large-scale, variable data, and provides powerful query and indexing capabilities.

You can use the following methods to delete documents in MongoDB: 1. The $in operator specifies the list of documents to be deleted; 2. The regular expression matches documents that meet the criteria; 3. The $exists operator deletes documents with the specified fields; 4. The find() and remove() methods first get and then delete the document. Please note that these operations cannot use transactions and may delete all matching documents, so be careful when using them.

To set up a MongoDB database, you can use the command line (use and db.createCollection()) or the mongo shell (mongo, use and db.createCollection()). Other setting options include viewing database (show dbs), viewing collections (show collections), deleting database (db.dropDatabase()), deleting collections (db.<collection_name>.drop()), inserting documents (db.<collecti

Deploying a MongoDB cluster is divided into five steps: deploying the primary node, deploying the secondary node, adding the secondary node, configuring replication, and verifying the cluster. Including installing MongoDB software, creating data directories, starting MongoDB instances, initializing replication sets, adding secondary nodes, enabling replica set features, configuring voting rights, and verifying cluster status and data replication.

MongoDB is widely used in the following scenarios: Document storage: manages structured and unstructured data such as user information, content, product catalogs, etc. Real-time analysis: Quickly query and analyze real-time data such as logs, monitoring dashboard displays, etc. Social Media: Manage user relationship maps, activity streams, and messaging. Internet of Things: Process massive time series data such as device monitoring, data collection and remote management. Mobile applications: As a backend database, synchronize mobile device data, provide offline storage, etc. Other areas: diversified scenarios such as e-commerce, healthcare, financial services and game development.

How to view MongoDB version: Command line: Use the db.version() command. Programming language driver: Python: print(client.server_info()["version"])Node.js: db.command({ version: 1 }, (err, result) => { console.log(result.version); });

MongoDB provides a sorting mechanism to sort collections by specific fields, using the syntax db.collection.find().sort({ field: order }) ascending/descending order, supports compound sorting by multiple fields, and recommends creating indexes to improve sorting performance.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.