.find is not a function in sails js mongodb

311 Views Asked by At

I have ArticlesController.js

const Articles = require('../models/Articles');

module.exports = {
  list: async(req, res) => {
    const articles = await Articles.find({});
    console.log(articles);
    res.status(200).json({
      message: 'Articles'
    });
  }
};

models/Articles.js

module.exports = {

  attributes: {
    title: {
      type: 'String'
    },
    body: {
      type: 'String'
    }
  },
  datastore: 'mongodb'
};

config/datastores.js

module.exports.datastores = {
  mongodb: {
    adapter: 'sails-mongo',
    url: 'mongodb://localhost:27017/sails-crud'
  },
};

package.json

"dependencies": {
    "@sailshq/connect-redis": "^3.2.1",
    "@sailshq/lodash": "^3.10.3",
    "@sailshq/socket.io-redis": "^5.2.0",
    "grunt": "1.0.4",
    "mongodb": "^2.2.25",
    "sails": "^1.4.2",
    "sails-hook-grunt": "^4.0.0",
    "sails-hook-orm": "^3.0.2",
    "sails-hook-sockets": "^2.0.0",
    "sails-mongo": "^1.2.0"
  }

But this is the error I get

error: Sending 500 ("Server Error") response: TypeError: Articles.find is not a function

I have tried using find.exec as well, same error with that as well. Help me resolve it.

0

There are 0 best solutions below