Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem fetching data from MongoDB from SailsJS
- // in file config/connections.js
- module.exports.connections = {
- // there are other irrelevant connections here as well
- mongodbServer: {
- adapter: 'sails-mongo',
- host: 'localhost',
- port: 27017,
- user: 'user1',
- password: 'password',
- database: 'myCollection'
- },
- }
- // in file config/models.js
- module.exports.models = {
- connection: 'mongodbServer',
- schema: false,
- migrate: 'safe'
- };
- //Here is my model in api/models/Accounts.js
- module.exports = {
- connection: "mongodbServer",
- attributes: {
- accounts: 'string'
- }
- };
- /*
- MongoDB myCollection has field called "accounts" which just has email accounts. For example
- {
- accounts: "abc@gmail.com"
- }
- */
- // I am try to access that list of accounts from my Controller like the following.
- index: function (req,res) {
- data = {
- "pageTitle": "Home",
- }
- Accounts.find().limit(5).exec(function(e,accounts){
- console.log(accounts)
- });
- return res.view("home/index",data);
- },
- // My problem is that console.log(accounts) is always empty.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement