Install MongoDB in windows

Source: Internet
Author: User
Tags create mongodb findone install mongodb
Download a stable version www.mongodb.orgwww.2cto.com from the official mongoDB website to decompress the downloaded package, and create two folders under the root directory, named data (storing data) and logs (storing logs) respectively ), create a mongodb instance in the logs folder. log File to record logs. Start the service and enter local in the browser

First download a stable version of http://www.mongodb.org/www.2cto.com on the mongoDB official website to download the compressed package decompress, and create two new folders under the root directory, respectively named data (store data) and logs (storing logs). Create a mongodb instance in the logs folder. log File to record logs. Start the service by entering http: // local in the browser

First download a stable version of http://www.mongodb.org/www.2cto.com on the mongoDB Official Website

Decompress the downloaded compressed package, create two folders under the root directory, name data (store data) and logs (store logs) respectively, and create mongodb under the logs folder. log File to record logs.

Start the service

Enter http: // localhost: 27017 in the browser to verify that the mongoDB service has successfully started www.2cto.com.

To add mongodb to the windows Service, perform the following operations:

4. After the MongoDB service is started, run the mongo command to start MongoDBshell.

Enter showdbs to display all the database names in the current database. You do not need to manually create a database in mongodb. You just need to use it directly. If there is no database engine, it will help us create them. This is somewhat different from traditional databases. There is no table concept in the database. Instead, it is a collection. mongodb does not support the join operation and you have to associate it yourself. Documents in the database can be understood as an object in BSON format.

1. showdbs displays the Database List.

2. useNorthwind enters the Northwind database, which is case sensitive.

3. showcollections displays the set in the database.

4. db is used to view the current database

5. Check the total number of records of the Customer in the database. Customer. count ().

6. Check the record of CustomerId = 1 in db. Customer. findOne ({_ id: 1 }).

Insert data

Item = {Key: 1, text: wokao, number: 3}

Db. table1.insert (item), mongo will create the set table1 and insert the item to complete the work of adding a new database.

Note: [each document has a member named _ id]. In fact, MongoDB creates such a document member for each document. The specified key and id are for MongoDB: they are not [document primary Keys]. MongoDB only recognizes _ id. You can specify them. If they are not specified, MongoDB will automatically add them.

Modify data

Vart = db. table1.findOne ({Id: 3}) to obtain a record

T. str = wo

Db. table1.update ({Id: 3, t })

Delete data

Db. table1.remove ({Id: 3 })

Query data

Db. table1.find () and db. table1.findOne ()

<, >=, <= Are not found in the query conditions of MongoDB. Instead, the operators $ lt, $ lte, $ gt, $ gte are used.

Create a collection

Db. ourdb. table1.save ({})

Delete collection

Db. table1.drop () or db. runCommand ({drop, table1 })

Delete Database

Db. runCommand ({dropDatabase: 1 })

Get server status information

Db. runCommand ({serverStatus: 1 })

We recommend a mongoDB graphical client software called MongoVUE.


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.