MongoDB Learning (i) installation configuration and simple application

Source: Internet
Author: User
Tags mongodb mongodb version

I. Installation and deployment 1, server-side installation

1. Download (official website https://www.mongodb.org/downloads/#production), fool installation, pay attention to modify the installation path.

Directory structure after the installation is complete:

In Bin, Mongo.exe is the client and Mongod.exe is the database:

2. Configure Environment variables

2, start the service side 1, the configuration data storage address

Create Data Catalog: D:\MongoDB\data

2, configuration log storage address

Create log directory: D:\MongoDB\log

On the command line, configure:

Attention:

1. After successful startup, there will be no prompt in the current console (no message is the best message).

2. In the log file, you can see if the startup was successful.

3. Do not close this command line.

3. View data, log folder and Demo.log file:

1. Data folder:

2. Log folder:

3. Open Demo.log:

In the Demo.log file, you can see if you have configured some information for success.

3. Start the Client

Enter Mongo.exe on the command line to display the following information:

Ii. the differences between MongoDB and other databases

III. application 1, common commands

1. Db.help () View command prompt:

2, DB view the current database name:

3. Use command use + database name to switch or CREATE database:

4, show DBS display database, you need to note that show DBS, will only show the library with data, no data library, is not displayed. In the DQS database, there is no data at the beginning, so it is not displayed, and when I insert a database, show DBS displays it.

5, db.dropdatabase () delete data from the current database:

6, Db.stats () View the status of the current data:

Explain:

"DB": "zt01", which indicates that the current database for "zt01" is described.

"Collections": 0, which indicates how many collections the current database has. You can view the collection of the current database by running show collections.

"Objects": 0, which indicates how many rows of data are in total for all collection in the current database. The displayed data is an estimate and is not very precise.

"Avgobjsize": 0, which indicates the average size of each row of data, is also an estimate, in bytes.

"DataSize": 0, which represents the total size of all data in the current database, not the size of the owning disk. The unit is bytes.

"Storagesize": 0, indicates that the current database occupies a disk size, the unit is bytes, because MongoDB has a pre-allocated space mechanism, in order to prevent when there is a large amount of data inserted on the disk pressure, so it will allocate more disk space beforehand.

"Numextents": 0, Number of events.

"Indexes": 0, which represents the number of System.indexes table data rows.

"Indexsize": 0, which indicates that the index occupies the disk size. Unit is bytes

"FileSize": 0, which indicates the file size of the current database pre-allocated.

7. Db.version () View MongoDB version:

8, Db.getmongo () View the IP of the currently connected machine:

9, Db.createcollection () Create a collection:

10,db. Collection. Drop() Delete collection:

11,db. Collection_name. Insert(document) :

MongoDB inserts data just as you would insert JSON data.

Document Document:json format string

{"_id": ObjectId ("5aa1e91d9f51d3ee8ed16453"), "title": "MongoDB Study", "by": "zt1994"}

12. The update () method is used to update a document that already exists:

Grammar:

1Db.collection.Update(2    <Query>,  query: The search condition for update, similar to where in SQL update query. 3    <Update>,  Update: The object of update and some updated operators (such as $, $inc ... ) can also be understood as the SQL update query within the set after the4    {5Upsert<Boolean>, upsert : Optional, this parameter means that if there is no record of update, insert objnew,true as INSERT, default is False, do not insert. 6Multi<Boolean>, Multi : Optional, mongodb default is False, only update the first record found, if this parameter is true, the condition is checked out all the records are updated. 7Writeconcern:<Document>  writeconcern : Optional, throws an exception level. 8    }9)

MongoDB Learning (i) installation configuration and simple application

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.