4

I am fairly new to sails and have followed a simple tutorial to create a REST api. I have created a model:

module.exports = {
  schema: true,
  attributes: {

    name: {
      type: "string",
      unique: true,
      required: true
    },

    role: {
      type: "string",
      required: true
    },

    group: {
      type: "string",
      required: true
    },

    email: {
      type: "string",
      unique: true,
      required: true
    },

    telephoneNumber1: {
      type: "string",
      required: true
    },

    telephoneNumber2: {
      type: "string",
    }
  }
};

The model contains some unique fields. I tested this out locally using both the sails localDisk and a real mongo DB running locally and everything was working i.e. when trying to add a duplicate it was rejecting it.

I then deployed to heroku and put in all the heroku config for the MongoLab and Redis. When testing I found that I could view all the entries using the index endpoint that I had created and I could also create new documents using the create endpoint. I then added a duplicate entry to the DB through the create url and found that it was allowing it and I was ending up with a load of documents that were identical.

I am using the 'sails-mongo' adapter. Is there something I need to do with the prod DB to apply the rules?

Thanks Alex

alexjfno1
  • 337
  • 1
  • 3
  • 14
  • Did you try adding dropDups: true to the unique fields ? It suppose to drop duplicates – teleaziz Dec 31 '14 at 17:42
  • Seems there are some issues with the unique within sails-mong and waterline, please have a look there : https://github.com/balderdashy/sails-mongo/issues/152 – MrVinz Jan 01 '15 at 08:28
  • Seems to be an ongoing issue. I tried the syncable: true flag but that didn't work. By the looks of it I will have to use the before hook to do the check myself. What I can't understand though is that it worked with a local mongo DB but not the one on Heroku – alexjfno1 Jan 02 '15 at 18:21

0 Answers0