In a production environment, Sails.js does not create MongoDB index/unique indexes defined in the models, so you would have to do it manually.
This hook solves it by using MongoDB's createIndex
function to create the indexes.
- Install the package using
npm install --save sails-hook-mongo-createindex
- Make sure you are using the
sails-mongo
database adapter - Lift the app:
sails lift
Just add unique
or index
to your model's attribute.
attribute: {
type: "string",
index: true
}
or
attribute: {
type: "string",
unique: true
}
If you find any bugs or want to improve the hook just open an issue or send a pull request, thanks!