Installation and use of MongoDB under Ubuntu

Source: Internet
Author: User
Tags install mongodb mongodb version mongo shell

This post describes MongoDB and details the reader's installation and use of MongoDB under Ubuntu. This tutorial was tested under Ubuntu14.04. (2017.09.07)

Installing MongoDB

MongoDB installation is very simple, no need to download the source files, can be installed directly with the Apt-get command.
Open terminal and enter the following command:

sudo apt-get install mongodb



After the installation is complete, enter the following command in the terminal to view the MongoDB version:

mongo -version


The output version information indicates that the installation was successful, as follows:

[Email protected]:/usr/src# mongo-version
MongoDB Shell version:2.4.9



Start and close the MongoDB command as follows:

service mongodb start
输入命令,结果如下:
[email protected]:/usr/src# service mongodb start
start: Job is already running: mongodb


service mongodb stop




Enter the following command to see if it started successfully:

-l   #注意:-l是英文字母l,不是阿拉伯数字1


Uninstalling MongoDB
sudo apt-get --purge remove mongodb mongodb-clients mongodb-server


Using MongoDB

Shell Command mode

Enter the mongo shell command mode, the default connection to the database is the test database, before you must make sure that you have started MongoDB, otherwise there will be an error, after starting to run successfully, such as:

[Email protected]:/usr/src# MONGO
MongoDB Shell version:2.4.9
Connecting To:test
Welcome to the MongoDB shell.
For interactive help, type ' help '.
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the Support group
Http://groups.google.com/group/mongodb-user
>
Common Operation Commands:

Db.help () Help on DB methods
Db.mycoll.help () Help on collection methods
Sh.help () sharding Helpers
Rs.help () Replica set helpers
Help Admin Administrative Help
Help connect connecting to a DB help
Help keys key shortcuts
Help Misc Misc Things to Know
Help Mr MapReduce

Show DBS Show Database names
Show collections show collections in current database
Show users show users in current database
Show profile Show most recent system.profile entries with time >= 1ms
Show logs show the accessible logger names
Show log [name] prints out the last segment of log in memory, ' global ' is default
Use <db_name> Set current database
Db.foo.find () List objects in collection Foo
Db.foo.find ({a:1}) List objects in Foo where a = = 1
It result of the last line evaluated; Use to further iterate
dbquery.shellbatchsize = X Set default number of items to display on shell
Exit quit the MONGO shell

Installation and use of MongoDB under Ubuntu

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.