MongoDB installation tutorial and simple operations in Ubuntu
1 MongoDB
First, let's start with a simple definition of MangoDB:
MongoDB is a distributed file storage-based database. Written in C ++. It is designed to provide scalable, high-performance data storage solutions for WEB applications.
MongoDB is a product between relational databases and non-relational databases. It has the most abundant functions and features like relational databases.
The following installation tutorial mainly follows the link obtained here:
Note that it seems that MongoDB does not have a 32-bit version, so select a 64-bit version first.
- First, go to the MongoDB official website and find the desired version of MangoDB. Replace the following command and execute it directly on the terminal. Remember to have a folder named Zhao Yi.
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 # unzip # Note permissions sudo mv mongodb-linux-x86_64-3.0.6 // usr/local/mongodb # copy the decompressed package to the specified directory for Installation
- Then add the MongoDB installation directory to the Path. Remember to replace it if your last location is different from mine.
Vi/etc/profile add export PATH =/usr/local/mongodb/bin: $ PATH and then source/etc/progile
- To start the database, I first use a non-default address, so I need to manually create a directory and specify the location. If the following statement is executed successfully, it indicates that the service is OK.
Mongod -- dbpath ~ /Data & (replace it with your database address here. You can customize it)
- Start shell and start playing
mongo
Then a shell will be started. Here we can start to operate our database.
2. Simple operation
Create a database (all the following databases are replaced by the mebiuw_db name. If you have different databases, change them on your own ):
Use mebiuw_db (replace with your database name)
View all current databases:
show dbs
Insert data:
db.mebiuw_db.insert({"name":"testdata"})
Delete a database (delete the database currently in use ):
db.dropDatabase()
Insert a document into a set and perform query. Note that the database is followed by the Set Name col, which can be changed by yourself. This is equivalent to the table name, which will be automatically created if it does not exist.
Db. col. insert ({title: 'mongodb tutorial ', description: 'mongodb is a Nosql database', tags: ['mongodb', 'database', 'nosql '], likes: 100 })
If you want to find these documents, you can use the find method of the corresponding set.
Db. col. find () or display more direct db. col. find (). pretty ()
For more MongoDB tutorials, see the following:
CentOS compilation and installation of php extensions for MongoDB and mongoDB
CentOS 6 install MongoDB and server configuration using yum
Install MongoDB2.4.3 in Ubuntu 13.04
MongoDB beginners must read (both concepts and practices)
MongoDB Installation Guide for Ubunu 14.04
MongoDB authoritative Guide (The Definitive Guide) in English [PDF]
Nagios monitoring MongoDB sharded cluster service practice
Build MongoDB Service Based on CentOS 6.5 Operating System
MongoDB details: click here
MongoDB: click here
This article permanently updates the link address: