NODE+MONGODB Operating Database

Source: Internet
Author: User
Tags install mongodb mongodb

1. Database (MongoDB) connection

(1) Install App Builder Express

NPM Install Express-generator-g

(2) Create an app

Express App Name

(3) Installing the MongoDB module

NPM Install MongoDB

(4) Page rendering type converted to HTML

A. Loading Ejs

1) npm Install Ejs

B.app.js Configuration

1) app.set (' View ', Path.join (__dirname, ' views '));

2) app.engine (' HTML ', require (' Ejs '). RenderFile);

3) App.set (' View engine ', ' html ');

Red Box switch

C. Change the jade file suffix in the views file under the application file to HTML

(5) Database connection

A. In the Application Folder cmd enter NPM start (provided that the MongoDB service is started)

No MongoDB Click here to open link * * *

2. Database (MongoDB) operations

(1) Creating a MongoDB database collection

Run MongoDB file path after starting MongoDB service +bin\mongo.exe

After performing show DBS you can see all the libraries of the service

Show Collections View All collections

Green is the newly created library

(2) inserting a document

Insertone can only insert one piece of data

Insertmany inserting more than one data

View data first switch library use library name

then query db. Collection name. Find ()

(3) Query data

CMD in Db.site.find () or Db.site.find (). ToArray ()

The others are not listed here Click here to open the link *****************

NODE+MONGODB Operating Database

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.