2

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

1 Answer 1

2

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...
  }

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.