The unique attribute of SailsJS and Mongo is ignored

It seems I cannot get a unique attribute to validate / validate unique values ​​when using Mongo in SailsJS. I get the same usernames. Any suggestions? I checked another post about this, but it was related to using Disk / Memory databases.

Sails 0.10.x with sails-mongo@0.10.x

Model:

module.exports = {

  attributes: {
    username:{
        type:'string',
        unique:true,
        required:true
    }
  }
};

Connections.js configuration file

mongo: {
    adapter: 'sails-mongo',
    host: 'localhost',
    port: 27017,
    schema:true,
    migrate: 'safe',
    database: 'mydatabase'
},
+4
source share
3 answers

Answered on GitHub here: https://github.com/balderdashy/sails-mongo/issues/181

migrate: 'safe', Waterline - . , "".

, migrate: 'safe' , Waterline . migrate: 'alter', .

+7

:

  • +

, , , , . mongodb , , , Waterline , , , .

0

I created a hook module that provides index creation in all environments https://github.com/didil/sails-hook-mongo-auto-index . Hope this helps, suggestions are welcome.

0
source

All Articles