Get the App
SLTechnology News&Howtos  ›  Database  › 

Install MongoDB on Linux platform

Shulou Source: shulou.com Published: 2022-06-01 17:33:23 10月24日 Update

MongoDB provides 64-bit installation packages for all linux distributions, which you can download from the official website.

Download address: https://www.mongodb.com/download-center#community

Download the installation package and extract the tgz (the installation on 64-bit Linux is demonstrated below).

Curl-O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz # download tar-zxvf mongodb-linux-x86_64-3.0.6.tgz # extract mv mongodb-linux-x86_64-3.0.6 / / usr/local/mongodb # copy the unzipped package to the specified directory

The executable file for MongoDB is located in the bin directory, so you can add it to the PATH path:

Export PATH=/bin:$PATH

The installation path for your MongoDB. Such as / usr/local/mongodb in this article.

Create a database directory

MongoDB's data is stored in the db directory of the data directory, but this directory is not automatically created during installation, so you need to manually create the data directory and create the db directory in the data directory.

In the following example, we create the data directory under the root directory (/).

Note: / data/db is the default MongoDB startup database path (--dbpath).

Mkdir-p / data/db

Run the MongoDB service on the command line

You can start the mongdb service by executing the mongod command in the bin directory in the mongo installation directory from the command line.

Note: if your database directory is not / data/db, you can specify it with-- dbpath.

/ mongod2015-09-25T16:39:50.549+0800 I JOURNAL [initandlisten] journal dir=/data/db/journal2015-09-25T16:39:50.550+0800 I JOURNAL [initandlisten] recover: no journal files present, no recovery needed2015-09-25T16:39:50.869+0800 I JOURNAL [initandlisten] preallocateIsFaster=true 3.162015-09-25T16:39:51.206+0800 I JOURNAL [initandlisten] preallocateIsFaster=true 3.522015-09-25T16:39:52.775+0800 I JOURNAL [initandlisten] preallocateIsFaster=true 7.7

MongoDB backend manages Shell

If you need to enter the MongoDB background management, you need to first open the bin directory under the mongodb installation directory, and then execute the mongo command file.

MongoDB Shell is an interactive Javascript shell that comes with MongoDB, which is used to operate and manage MongoDB.

When you enter the mongoDB background, it will link to the test document (database) by default:

$cd / usr/local/mongodb/bin$. / mongoMongoDB shell version: 3.0.6connecting to: testWelcome to the MongoDB shell.

Because it is a JavaScript shell, you can run some simple arithmetic operations:

> 2x 24 > 3m 69

Now let's insert some simple data and retrieve the inserted data:

> db.runoob.insert ({nInserted 10}) WriteResult ({"nInserted": 1}) > db.runoob.find () {"_ id": ObjectId ("5604ff74a274a611b0c990aa"), "x": 10} >

The first command inserts the number 10 into the x field of the runoob collection.

MongoDb web user interface

MongoDB provides a simple HTTP user interface. If you want to enable this feature, you need to specify the parameter rest at startup.

$. / mongod-dbpath=/data/db-rest

MongoDB has 1000 more Web interface access ports than service ports.

If your MongoDB running port uses the default 27017, you can access the web user interface at port 28017, that is, http://localhost:28017.

Tags: Directory data command database interface background user interface port path service management run interactive address file function parameter slogan can be accessed through the Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Docker Shulou Technology Apple NVidia