MongoDB download installation test and use

Source: Internet
Author: User
Tags mongodb download win32

1. Download and install

level:mongodb-win32-x86_64-enterprise-windows-64-2.6.4-signed.msi

Http://downloads.mongodb.com/win32/mongodb-win32-x86_64-enterprise-windows-64-2.6.4-signed.msi?_ga= 1.238525191.607472782.1411452026

level:mongodb-win32-i386-2.6.5.zip

https://fastdl.mongodb.org/win32/mongodb-win32-i386-2.6.5.zip?_ga=1.181732967.1708362836.1411364634

2. installation directory:

Install the app under this directory:

D:\MongoDB\

3. create a new directory

D:\MongoDB\data\db

D:\MongoDB\data\log

4. start the town:

CD D:\MongoDB\bin

Mongod-dbpath "D:\MongoDB\data\db"

5. Test the connection

Open a new cmd window, enter the MongoDB bin directory, enter MONGO or Mongo.exe , the following message appears indicating that the test passed, at which point we have entered the Test This database, how to enter the other database below will say.

Enter exit or Ctrl + C to exit.

6. when mongod.exe is turned off,mongo.exe cannot connect to the database, so every time you want to use MongoDB The database has to be turned on Mongod.exe program, so it's more troublesome, at this point we can MongoDB installed as Windows Service

or run cmd, go to the bin folder and execute the following command

Console execution command:d:\mongodb\bin>

Mongod--dbpath "D:\MongoDB\data\db"--logpath "D:\MongoDB\data\log\MongoDB.log"--install--servicename "MongoDB"

Here --mongodb.log is the start of the log file,--servicename "MongoDB" service named MongoDB.

Then start the mongodb service

 > D:\mongodb\bin>net START MongoDB

Open Task Manager and you can see that the process has started

7. shutting down services and deleting processes

> D:\mongodb\bin>net Stop MongoDB ( close service )

>d:\mongodb\bin>mongod--dbpath "D:\MongoDB\data\db"--logpath "D:\MongoDB\data\log\MongoDB.log"--remove-- ServiceName "MongoDB"

( Delete, note not --install .)

Ii. use of MongoDB

1. Common Commands

Show DBS display database list

Use dbname into the dbname database, case sensitive, no this database does not matter

Show Collections displays a collection in the database, equivalent to a table

2. Create & Add

Db.users.save ({"Name": "LECAF"}) created a collection called users and added a new {"name": "LECAF"} of Data

Db.users.insert ({"Name": "Ghost", "Age": ten}) inserts a new data in the users collection, if no users This collection,mongodb will automatically create

There is a slight difference between save () and Insert () : If the new data primary key already exists,Insert () will not do the operation and prompt the error, and Save () change the original content to the new content.

Existing data:{_id:1, ' name ': ' N1 '} ,_id is the primary key

Insert ({_id:1, "name": "N2"}) will prompt for an error

Save ({_id:1, "name": "N2"}) will change N1 to n2 , with update

3. Delete

Db.users.remove () delete All data under the Users collection

Db.users.remove ({"Name": "LECAF"}) deletes data NAME=LECAF under the users collection

Db.users.drop () or db.runcommand ({"Drop", "users"}) Delete collection users

Db.runcommand ({"Dropdatabase": 1}) Delete the current database

4. Find

Db.users.find () find All data in the Users collection

Db.users.findOne () to find The first data in the users Collection

5. Modifications

Db.users.update ({"Name": "LECAF"}, {"Age": ten}) modify the NAME=LECAF data to age=10 , the first parameter is the lookup condition, the second parameter is the modification content, except the primary key, the other content will be replaced by the contents of the second parameter, the primary key cannot be modified,

 

Third, advanced applications

1. Condition Lookup

Db.collection.find ({"Key": value}) find data for Key=value

Db.collection.find ({"key": {$gt: Value}}) key > value

Db.collection.find ({"key": {$lt: Value}}) key < value

Db.collection.find ({"key": {$gte: Value}}) key >= value

Db.collection.find ({"key": {$lte: Value}}) key <= value

Db.collection.find ({"key": {$gt: value1, $lt: value2}}) value1 < key <value2

Db.collection.find ({"key": {$ne: Value}}) key <> value

Db.collection.find ({"key": {$mod: [1]}}) modulo operation, equivalent to key% = = 1 i.e. key c4> divided by a remainder of 1.

Db.collection.find ({"key": {$nin: [1, 2, 3]}) does not belong, the condition equal to the value of key does not belong to [1, 2, 3] Any one of the c4>

Db.collection.find ({"key": {$in: [1, 2, 3]}) , the condition equals key equal to [1, 2, 3] in any What one

Db.collection.find ({  "key"  : {  $size:  1 } })     $ Size  key 1 ( must be an array, The case of a value cannot be counted as 1

Db.collection.find ({"key": {$exists: True|false}}) $exists field exists,true returns the existence field key of data, false returns the non-existent word degree Key of Data

Db.collection.find ({"Key":/^val.*val$/i}) Regular, like ; "i" ignores case, " m"supports multiple lines

Db.collection.find ({$or: [{a:1}, {b:2}]}) $or or (note:MongoDB 1.5.3 later version is available), eligible a=1 or qualifying b=2 data will be queried.

Db.collection.find ({"Key": Value, $or: [{a:1}, {b:2}]}) meets the criteria key=value , while complying with any of the other two conditions One of the data

Db.collection.find ({"Key.subkey": Value}) The values in the inline object match, note:"Key.subkey" must be quoted

Db.collection.find ({"key": {$not:/^val.*val$/i}}) this is an operator that is used in combination with other query conditions and is not used alone. The result set obtained by the above query condition plus $not can get the opposite set.

2. sorting

Db.collection.find (). Sort ({"Key1":-1, "Key2": 1}) here the 1 stands for Ascending,-1 for Descending

3. other

Db.collection.find (). Limit (5) controls the number of returned results, and if the argument is 0, thelimit () will not work if it isnot constrained

Db.collection.find (). Skip (5) controls how many amounts are skipped for the returned result, and if the argument is 0,Skip () will not work if the parameter is not constrained. or skipped 0 .

Db.collection.find (). Skip (5). Limit (5) can be used for paging, skipping 5 data and then fetching 5 Data

Db.collection.find (). Count (True) count () returns the number of result set bars

Db.collection.find (). Skip (5). Limit (5). Count (True) at join Skip () and limit () In both operations, a parameter of true is required to obtain the actual number of results returned, Otherwise the total number of results that match the query criteria is returned.

MongoDB download installation test and use

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.