MongoDB Basic Tutorial Series--Second MongoDB basics operation (i)

Source: Internet
Author: User
Tags mongodb server mongodb version

1. Installation Environment

Download the latest version of MongoDB on the official website and download the correct MongoDB version according to your own version of Windows. After downloading, double-click the 32-bit or 64-bit. msi file and follow the instructions to install it.

Description

    1. The 32-bit version of MongoDB only supports databases below 2G and is only available for testing and evaluation.
    2. Windows XP systems are no longer supported after the MongoDB 2.2 release. The latest version also has no installation files for the 32-bit system.

Create Data Catalog

After MongoDB is installed, we need to create a data directory. Note that the data directory should be placed under the root directory (e.g. C: \ or D:\. , etc.).

Create the Data\db folder in the C drive,

Running the MongoDB server

1. Open Cmd.exe, navigate to the MongoDB Bin directory you just installed, and go to the MongoDB installation folder. The directory where I installed MongoDB is: C:\Program files\mongodb\server\3.4\bin

2. Set the DBPath path in Mongod.exe to specify the replacement path for \DATA\DB. Such as

MongoDB Background Management Shell

Open the Bin directory under the MongoDB installation directory and execute the Mongo.exe file, the MongoDB shell is the interactive JavaScript shell with MongoDB's own interactive environment for manipulating and managing MongoDB.

Since it is a JavaScript shell, you can run some simple arithmetic operations:

The db command is used to view the document (database) of the current operation:

Note: When you enter MongoDB background, it is linked to the test document (database) by default.

2. Database operation

2.1. Create a Database

MongoDB use creates the database in the same way as the database name. useA new database is created, and if the database exists, the database is returned.

Format

Use database_name

Example

Create a database named "Liruihuan"

>use liruihuanswitched to DB Liruihuan

Use DB to view the database for the current operation

>dbliruihuan

Check the database list using show DBS

>show dbsadmin    0.000GBlocal      0.000GB

Found that the newly added "Liruihuan" database was not found in the list, because at least one document was inserted to be displayed.

> Db.user.insert ({"Name": "Liruihuan"}) Writeresult ({"ninserted": 1}) > show dbsadmin   0.000GBliruihuan  0.000GBlocal    0.000GB

Note: in MongoDB, the default database is test, and if you do not create any databases, the collection is saved in the test database.

2.2. Delete Database

MongoDB uses a command to delete an existing dropDatabase() database.

Format

Db.dropdatabase ()

Example

First look at the list of databases using show DBS

> Show dbsadmin   0.000GBliruihuan  0.000GBlocal    0.000GB

Use Dropdatabase () to delete a database Liruihuan

>use liruihuanswitched to DB liruihuan>db.dropdatabase () >{"dropped": "Liruihuan", "OK": 1}>

Then use show DBS to look at the list of databases

>show dbsadmin    0.000GBlocal      0.000GB

The discovery database "Liruihuan" has been deleted

When you feel inferior to others or decadent, it is time to calm down and precipitate something.

If you think this article is good or helpful to you, you can give bloggers a little encouragement and support through the "reward" function on the right.

MongoDB Basic Tutorial Series--Second MongoDB basics operation (i)

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.