I am new to Sails.js. I am trying to fetch data from my Mongo Db database "TestDB", I have a collection name "Components", so I created a Model named Components whcih contains the attributes of my colection
Components.js
module.exports = {
attributes: {
TaskId: {
type: 'string',
required: true
},
CompName: {
type: 'string'
},
InitialAttr: {
type: 'string'
},
Value: {
type: 'string'
}
}
};
ComponentsController.js
module.exports = {
GetComponentList : function(req, res){
Components.find({ CompName: 'ImageComponent'}).exec(function(err, data) {
if (err) return next(err);
res.json(data);
});
}
};
Route:
'/comp' : {
controller: 'components',
action: 'GetComponentList'
}
The above query executes fine in MongoVUE returning the dataset, but returns
[]
in Sails.js
The Waterline ORM expects all database tables / collections to be lowercased. I'm guessing if you looked in your Mongo database you'd see there are now two collections: Components and components. If you don't care about the existing data in your db you can just delete the Components collection. Otherwise you can point your model at the existing collection using the tableName property:
module.exports = {
tableName: 'Components',
attributes: {
TaskId: {
type: 'string',
required: true
},
...etc...
}
}