MongoDB: getting started with mongodb installation and addition, deletion, modification, and query

Source: Internet
Author: User
Tags mongodb client

I. Download

On the official MongoDB website, we found that there are 32bit and 64bit, which depends on your system, but here are two points of attention:

①: According to industry rules, the even number is "stable version" (for example, 1.6.X, 1.8.X), and the odd number is "development version" (for example, 1.7.X, 1.9.X ), I believe everyone knows the difference between the two versions. The latest version is 2.4.

②: 32-bit mongodb can only store up to 2 GB of data, and 64bit is unlimited.

Here I will download "2.2.6, 32bit", OK. After the download, I will put it on the "F disk" and change the folder name to "mongodb".

Ii. installation is not performed.

What do you mean? Actually, you just need to decompress it to the directory you want to install. I will decompress it to the F: \ mongodb directory.

Create a new folder db to store mongodb data,

Start mongodb:

Open cmd, enter the mongodb installation directory, and enter the following command: mongod -- dbpath = F: \ mongodb \ db (specify the data storage folder)

Check whether the installation is successful. In this example, the mongodb port is 27017. Enter http: // localhost: 27017/in the browser, for example:

Change the port to 28017 to view more mongodb Management Information: http: // localhost: 28017/For example:

III. Basic operations

As it is an entry point, let's just talk about the addition, deletion, modification, and query of mongodb.

First, open cmd, enter the mongodb installation folder, run the mongo command, and open the mongodb shell, which is the mongodb client. It is also a js compiler, the "test" database is connected by default.

1. Before inserting data, let's talk about three elements in mongodb: database, set, and document. "set" is the "table" in the corresponding relational database ", "document" corresponds to "line ".

The database has a set. The next step is the set. Here, the set name is "person". Note that the document is in the json extension (Bson) format.

Code:

nosql:db.person.insert({"name":"jack","age":20})nosql:db.person.insert({"name":"joe","age":25})

2. query operations

db.person.find()

"_ Id": this field is the GUID that the database adds by default. The purpose is to ensure data uniqueness.

3. Modify the update operation

The first parameter of the update method is "Search Condition", and the second parameter is "update value". I have learned C # and believe it is quite understandable.

db.person.update({"name":"joe"},{"name":"joe","age":30})
4. delete operations

If no parameter is included in the remove operation, all data will be deleted. It is a very dangerous operation. It is an irrevocable operation in mongodb. Think twice before you proceed.

To sum up, mongodb is easy to get started with. It seems that many things are to be done and cannot be simply thought about. I will continue to add, delete, modify, and query details later.

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.