WIN10 installation of MongoDB and configuration and basic use of MONGODB (node environment)

Source: Internet
Author: User

MongoDB Installation  :Https://www.mongodb.com/download-center after downloading, we click Mongodb-win32-x86_64-2008plus-ssl-3.4.3-signed.msi ( For the latest version of the 2017.4.16 update) in the installation path: D:\MongoDB\Server\3.6\

MONGDB Environment Configuration

First, we first create a file named "Mongod.config" in the Bin directory, and enter it in:

 

# #database directorydbpath=d:\mongodb\data# #log Filelogpath=d:\mongodb\log

  

To configure environment variables:

Desktop My Computer, right-click Properties, advanced system settings, environment variables, as follows:

Start the database 1. Command line open service
-- Dapath D:\MongoDB\data
or use
-- dbpath "D:/mongodb/data"--logpath "D:/mongodb/log/mongodb.log"--logappend
(resolution: Mongod--dbpath command is to create a database file storage location, the start of the MongoDB service needs to determine the location of the database files, or the system will not be automatically created, startup will not be successful. --logpath indicates that the log file is stored in a path--logappend means that the log file is written in append mode) 2. Set the service to system service
" d:\MongoDB\Server\3.6\bin\mongod.exe--service--dbpath d:\MongoDB\data--logpath=d:\mongodb\log\mongodb.log-- Logappend--directoryperdb"
This line of command creates a service item that we can view in the following way: "Win+r" into the "Run" interface, enter "Services.msc" into the "service"-

Then go to the following interface, we can see in the name here you can see a service item named "MongoDB", and then click the right mouse button, "Start" the service item.

Here, our service is started successfully, another way to start the service is: start cmd as an administrator, enter in cmd:

#net Start MongoDB

Then the advent of the MongoDB service starts successfully with the words stating that we started the service successfully!

The basic curd of MongoDB

Connect to MongoDB Database
Const MONGOOSE = require (' Mongoose ') mongoose.connect (' mongodb://localhost/test '= Mongoose.model ( ' user ', {name:string, age:number}, ' users ')
Delete data
// Delete Data User.remove ({name: ' Rose '}, (err, result) = =    {ifreturn  console.log (Err)    Console.log (Result)    //  Here Results Delete result    //  {n: Delete a few data, OK: 1 = delete succeeded}

Save data
// Add Data New User ({name: ' Rose ' })    Rose.save (function  (err) {    if  (err) {          Console.log (Err)     Else  {          console.log (' Save succeeded! ') )     }})

Update all data that meets the criteria
User.updatemany ({name: ' Rose '}, {age:28}, (err, result) = =    {ifreturn  Console.log (Err)    console.log (Result)    //  results deleted here //      {     //  N: Found several data,    //  nmodified: Modified several data,/    /  OK: 1 for Change success}})
Querying all data
// querying all data that satisfies the criteria User.find ({name: ' Rose '}, (err, data) = =    {ifreturn  console.log (Err)    Console.log (data)    // data Here is an array, which is the query out of all the information })

Querying a single piece of data
// query out a single piece of data User.findone ({name: ' Rose '}, (err, data) = =    {ifreturn  console.log (Err)    Console.log (data)    //  The data here is an object, is a piece of information!

The basic use of MongoDB is these, I believe you have a certain understanding of MongoDB, and hope to gentlemen useful

For more commands, here's a good blog post: https://www.cnblogs.com/lecaf/archive/2013/08/23/mongodb.html

WIN10 installation of MongoDB and configuration and basic use of MONGODB (node environment)

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.