node. JS---Sails project development (4)---Configure MongoDB database connection

Source: Internet
Author: User

1, the installation of sails to MONGO dependence

NPM Install Sails-mongo--save

2. Configure MONGO Connection

Modify Config/connections.js:

Module.exports.connections = {somemongodbserver: {    adapter: ' Sails-mongo ',    Host: ' 127.0.0.1 ',    port: 27017,    User: ' Test ',//optional    password: ' Test ',//optional    database: ' Sails '//optional  }};

3, the basic configuration of the model layer

Modify Config/models.js, configure the connection database bit MongoDB for the model, and add Updatedat and Createdat properties for each model:

Module.exports.models = {  migrate: ' Alter ',  ' connection ': ' Somemongodbserver ',  autocreatedat:true,  Autoupdatedat:true};

Here are some instructions for migrate:

Safe-never auto-migrate My database (s). I will does it myself (by hand) [does not automatically merge data and requires manual control]
Alter-auto-migrate, but attempt to keep my existing data (experimental) [automatically merged with old data, when a new field is added, the datasheet will not be deleted, it is recommended]
Drop-wipe/drop all my data and rebuild models every time I lift sails[Delete datasheet, create new table, insert new data]

4, modify the Config/env/development.js

Module.exports = {  models: {    connection: ' Somemongodbserver '}  };

5. Next, we start sails

Sails lift

  

node. JS---Sails project development (4)---Configure MongoDB database connection

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.