Installation and use of MongoDB under Win7

Source: Internet
Author: User
Tags mongodb

Installation and use of MongoDB under Win7

1. Download:

Http://www.mongodb.org/downloads

2. Installation:

The installation directory is D:\mongodb\MongoDB 2.6 Standard

Configure environment variable path is D:\mongodb\MongoDB 2.6 standard\bin

D:\mongodb\ Create a Data folder for storing database files

3, start the server:

CMD input Mongod.exe--dbpath d:\mongodb\data

If you start properly, you will see a prompt similar to the following:
...
[Initandlisten] MongoDB starting:pid=7476 port=27017 Dbpath=d:\mongodb\data
...
[Initandlisten] Waiting for connections on port 27017

Do not turn off the server when it is turned on.

4, start the client:

Open a new cmd console, enter command Mongo.exe

If you successfully connect to the server, you will see a prompt similar to the following:

MongoDB Shell version:2.6.5
Connecting To:test
Welcome to the MongoDB shell.
For interactive help, type ' help '.
For more comprehensive documentation
http://docs.mongodb.org/
Questions? Try the Support group
Http://groups.google.com/group/mongodb-user
>

5, the operation of the database:

Show all databases
Show DBS

Displays all tables under the current database
Show collections

Inserts data into the X123 table (automatically created if the table does not exist)
Db.x123.insert ({name: ' abc123 ', Age: ' 20 '})

Display all data in the x123 table
Db.x123.find ()

Conditional query
Db.x123.find ({"Test5": "OK"}). Limit (1);

Delete the data with the Name field ' abc123 '
Db.x123.remove ({name: "abc123"})

Update action
Db.x123.update ({"Count": {$gt: 5}},{$set: {"Test5": "OK"}},true,true);

More commands are as follows:

Using the specific DB
Use Xxdb;

Delete the specified database, you must use Xxdb again
Db.dropdatabase ();

Delete Collection
Db.xxcollection.drop ();

View the records in collection
Db.xxcollection.find ();

Delete a record
Db.xxcollection.remove ({_id:xxx});

Export data, data format as JSON
Mongoexport--port 10240-d xxdb-c xxcollection-o xxcollection.dat;

Export data formatted as CSV (comma-separated values)
Mongoexport--port 10240-d xxdb-c xxcollection-csv-f uid,username,age-o;

Import data, data format as JSON
Mongoimport--port 10240-d xxdb-c xxcollection-o xxcollection.dat;

Import data, data format is CSV, do not import first row (the Behavior column name)
Mongoimport--port 10240-d xxdb-c xxcollection--type csv--headerline-file user_csv.dat;

Query a record
Db.xxcollcetion.findOne ();

query specifies the number of bar records
Db.xxcollection.find ({xxx:xxx}). limit (n);

Sort
Db.xxcollection.find ({xxxx:xxxx}). Sort (' date ', 1);
  
Paging
Db.xxcollection.find ({memberid:test}). Skip (20n). Limit. Sort (' date ', 1);

6. Visualization Tools:

Reference: http://docs.mongodb.org/ecosystem/tools/administration-interfaces/

7, C # operation MongoDB:

Reference: Https://github.com/mongodb/mongo-csharp-driver/downloads

Supplemental "MongoDB Installation and Windows boot":
Create a new logs folder inside D:\mongodb
Create a new Mongodb.log file inside the logs folder
Open the cmd window and enter the following command:
Mongod--dbpath D:\mongodb\data--logpath=d:\mongodb\logs\mongodb.log--install
Then enter the following command:
net start MongoDB
The display is as follows:
The MongoDB service is starting.
The MongoDB service has started successfully.
Then go to the service and MongoDB.
If it is Win7, then start CMD to use Administrator to start.
In addition, the visualizer NoSQL Manager for MongoDB works well.

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.