0

I am a newbie in sails.js framework(and for node.js) and I have created myself an API from the address bar using sails.js features. my question is how do I transfer this data to mongodb so I can see it visually.

I have tried to follow this guide: https://www.npmjs.org/package/sails-mongo but its for 0.9 sails version(current version is 0.10) so that a lot of files that I needed to change has been modified and gone/renamed. I couldn't find an updated tutorial as well so if anyone can please write down how can I implement mongoDB to my sails project that would be wonderful.

Matan Gubkin
  • 3,019
  • 6
  • 25
  • 44

2 Answers2

2

In config/connections.js you need to configure your mongoDB connection. Then go to config/models.js, uncomment the connection property and set the name of your mongoDB connection.

sgress454
  • 24,870
  • 4
  • 74
  • 92
Lyntik22
  • 23
  • 6
0

In config/connection.js, You can configure your MongoDb connection like this.

module.exports.connections = {
  MongoConnection: {
    adapter: 'sails-mongo',
    host: 'localhost',
    port: 27017,
    // user: 'username',
    // password: 'password',
    database: 'DB_Name'
  }
};

You need to install sails-mongo package using npm in your working folder.

Then in config/models.js, Add the name of your mongoDb connection like this:

module.exports.models = {                                                                          
   connection: 'MongoConnection',                                                                     
   migrate: 'alter'
};

Thats it, you are ready to go.