Mongodb Learning (1)

Source: Internet
Author: User
Tags install mongodb

I recently heard that mongodb is very popular, so I downloaded and learned something about mongodb. I will discuss it later.

My machine system is ubuntu13.04. There are two ways to install mongodb: 1. Download the tar-gz package, decompress it, and install 2. Use the ppa source for installation. Because I chose method 2 for simplicity.

Import the public key first:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

Then we need to create:

echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list


File to facilitate mongo access using command lines

Not to mention

sudo apt-get update

And
sudo apt-get install mongodb-10gen

The installation is simple, but it is still complicated.

Common commands

sudo service mongodb startsudo service mongodb stop

Mongo is enabled and disabled.

Next, go to the shell interface of the mongo we just installed:

Enter mongo in the terminal to display the following interface.

By default, we entered the mongo test database. We will not go to the details of the following warnings.

I just found a major mongo problem. I just suspended my computer and failed to wake up when it was turned on. After forced shutdown, mongo could not be used! Today, google often finds out what it is, and there is a suffix below/var/lib/mongodb. you can use mongo normally after deleting the lock file.

Now that we can use shell to access mongo, we can perform the most basic function of the database: add, delete, query, and modify.

First, we connect to the test database, so we will use the test database for simple testing.

Input in shell

db.test.save({a:1})
After the process ends, we store a piece of content in the mongodb test database. Let's take a look:

db.test.find()
At this time, we found that the data we just entered appeared in the shell.

We also see our input data.

We need our mongodb to start at random, so we need to modify it.

sudo gedit /etc/rc.local
We add
/usr/local/mongodb/bin/mongod -dbpath=/usr/local/mongodb/data/db --port 27017-logpath=/usr/local/mongodb/log --logappend
Well, save it so that mongodb will start with the computer.



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.