MongoDB, node. JS Installation

Source: Internet
Author: User
Tags findone log log

1, official website Download Mongodb-win32-x86_64-2008plus-ssl-3.4.6-signed.msi installation package

2. Install to D:\database\mongoDB (new this directory folder)

3, to the Bin folder, see the Mongod.exe command, or the environment variable configuration, not every time in DOS to switch to this file directory

4. Install as a service

--dbpath is the specified database storage directory, there are two "-"

Installing MongoDB as a Windows service is simple, just add--install after the command line that you executed above
According to the normal plot, the service should be installed successfully, but unfortunately, the following prompt appears
--install have to is used with--logpath

So merge a sentence:

Mongod--dbpath=d:\database\mongodb\db--logpath=d:\database\mongodb\log\log.txt-install-servicename "MongoDB"

This is a command-line window that prints some startup information, and the last line displays the following information to indicate that the boot was successful.

2014-04-23t10:38:48.391+0800 [Initandlisten] waiting for connections on port 27017

This is the browser input http://localhost:27017/can see the display information for

It looks like you is trying to access MongoDB over HTTP on the native driver port.
5. Start the service:
net start MongoDB

Always error, 100, service can not start, after Baidu, as long as the DB Mongod.lock, Storage.bson two folders deleted and then executed, you can start a successful service

6. Enter MongoDB's shell interface Mongo.exe

7, 10. Prompt command Help

View all databases Show DBS
Switch database
Use DbName
For example: Use admin
At this point, you can already add the data
Db.yourCollectionName.insert (object)
Example: Db.majt.insert ({name:majt,age:22})
Because after you add data, MongoDB automatically creates a collection of stored data
Of course, you can also create collections (that is, tables)
Db.createcollection (Name,{size:...,capped:...,max: ...})
View Collections
Show collections
View the name of the collection so
Db.getcollectionnames ()
View the status of all collections
Db.printcollectionstats ()
Delete Collection
Db.collectionName.drop ()
Example: Db.majt.drop ()
Modify the collection name
Db.majt.renameCollection (NewName)
Querying the specified collection
Db.getcollection (CollectionName)
Example: Db.getcollection ("Majt")

Data

Add data
Db.collectionName.save (obj)
Example: Db.majt.save ({name: "Maumoon", age:22})

Delete data
Db.collectionName.remove (obj)

modifying data
Db.collectionName.update (obj)
For example: Db.majt.update ({name: "Maumoon"},{$set: {age:27}},false,true)
Db.majt.update ({name: "Maumoon"},{$inc: {age:1}},false,true)

Querying data
Db.collectionName.find (obj)
Example: Db.majt.find ({name: "Maumoon"})

Querying All records
Db.collectionName.find ()
Equivalent to select * from CollectionName;
20 records are displayed by default, with it command paging

Statistics all the data in the collection
Db.collectionName.find (). Count ()
Example: Db.majt.find (). Count ()

Sort
Ascending Db.collectionName.find (). Sort ({age:1})
Example: Db.majt.find (). Sort ({age:1})
Descending Db.collectionName.find (). Sort ({age:-1})
Example: Db.majt.find (). Sort ({age:-1})

Data before querying a piece of data
Db.collectionName.find (). Limit (number)
Example: Db.majt.find (). Limit (2)
Querying data after a piece of data
Db.collectionName.find (). Skip (number)
Example: Db.majt.find (). Skip (2)
Querying for data between XXX
Db.collectionName.find (). Limit (n). Skip (M)
Example: Db.majt.find (). Limit (3). Skip (1)

Query the first piece of data for a collection
Db.collectionName.findOne ()
Example: Db.majt.findOne ()

Query the first qualifying data in a collection
Db.collectionName.findOne (obj)
Example: Db.majt.findOne ({age:21})

The value of name in the query collection is Maumoon data
Db.collectionName.findOne (obj)
Example: Db.majt.findOne ({name: "Maumoon"})
Equivalent to select * from CollectionName where name= ' Maumoon ';

The value of name in the query collection contains the data of M
Db.collectionName.findOne (obj)
Example: Db.majt.findOne ({name:/m/})
Equivalent to select * from CollectionName where name= '%m% ';

Query the value of name in the collection with the data starting with M
Db.collectionName.findOne (obj)
Example: Db.majt.findOne ({name:/^m/})
Equivalent to select * from CollectionName where name= ' m% ';

Data in the query collection that has an age value equal to 22
Db.collectionName.find (obj)
Example: Db.majt.find ({age:22})
Equivalent to select * from collectionname where age = 22;

Querying data for age in a collection that is greater than 22
Db.collectionName.find (obj)
Example: Db.majt.find ({age:{$gt: 22}})
Equivalent to select * from CollectionName where age > 22;

Data in the query collection that has an age value of less than 22
Db.collectionName.find (obj)
Example: Db.majt.find ({age:{$lt: 22}})
Equivalent to select * from CollectionName where age < 22;

Data in the query collection that has an age value greater than or equal to 22
Db.collectionName.find (obj)
Example: Db.majt.find ({age:{$gte: 22}})
Equivalent to select * from CollectionName where age>=22;

Data in the query collection that has an age value less than or equal to 22
Db.collectionName.find (obj)
Example: Db.majt.find ({age:{$lte: 22}})
Equivalent to select * from CollectionName where age<=22;

Data in the query collection that has an age value greater than 21 and less than 27
Db.collectionName.find (obj)
Example: Db.majt.find ({age:{$lt: $, $GT: 21}})

Or
Db.collectionName.find ({$or: [{age:22},{age:21}]})
Example: Db.majt.find ({$or: [{age:22},{age:21}]})
Equivalent to select * from CollectionName where age=22 or age=25;

Filter the value of age in the collection duplicate data
Db.collectionName.distinct ("name")
Example: Db.majt.distinct ("Age")

Mongovue Installation

Not many, download, then install, after installation is complete

Replace the "MongoVUE.exe" file in the "Cracked Patches" folder in the unzip zip under the installation file directory (see the World Spring Xuan Project)

And, of course, there's a problem here.

about Mongodbvue Unable to display collection solution

MongoDB new storage Engine for Wiredtiger, under this storage engine, we use the visualizer Mongovue is unable to see collection should be replaced with MMAPV1 engine 1, delete the Data folder, and then recreate Data2, Execute Mongod  --storageengine mmapv1--dbpath Data Catalog
Example: Mongod--storageengine mmapv1--dbpath=d:\database\mongodb\db

Establish a connection

Basic Operations Create a table

Right-click on the database to add Collection, such as:

Add Data

Select the table you just added, right-click, select Insert/import Documents, such as:

View Log Log

db.Test.insert({    Name:"张三", Age:23, Sex:"男", Add:"XXX市XXX号XXX街道XXX号"});





MongoDB, node. JS installation

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.