MongoDB Beginner (a) the configuration of the environment

Source: Internet
Author: User

A. MongoDB installation

1. First download its installation package http://www.mongodb.org/on the official website of MongoDB. Download it according to your operating system.

2. Establish two directories on the hard disk to store MongoDB installation files and data files, for example, I created:

D:\mongodb and D:\mongodbdata

Unzip the downloaded installation package and copy the extracted items to the D:\mongodb.

3. Start cmd (win+r key, cmd) to switch to the Bin folder in D:\mongodb.

Input command: Mongod.exe--dbpath D:\mongodbdata the database is installed.

4. Configure the environment variables. Add D:\mongodb\bin to Path

5. You can enter mongod-help in cmd to view Mongdb's help.

Two. Start the database

Create a new BAT file (to open the database file):

Input content: Mongod--dbpath D:\mongodbdata

Create a new BAT file (Database operations file):

Input content: MONGO 127.0.0.1:27017/admin

It means to access the database port number 27017 (the default port) via the 127.0.0.1 URL, with Admin user access

Three. Comparison of databases


Four. Simple operation of the database

1. New database use [DbName]

[DbName] is the name of the database. The database is not saved if the database is not operational after the new database is created

2. Add a collection to the database (you can understand it as a new table) and add a record (adding data to the table)

Db.persons.insert ({name: "Zhangsan"})

3. Querying all the databases

Show DBS

4. Querying documents in the database

Show collections

5. Querying data in a database document

Use the Find () method or the FindOne () method

6. Modify the Database

Db.persons.update ({name: "extjs4.0"},{$set: {name: "extjs4.1"}})

Similar to that in SQL
Update persons Set name = ' extjs4.1 ' WHERE name = ' extjs4.0 '

7. Delete Data

Db.persons.remove ({name: "extjs4.0"})


Example:




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.