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