10

A very simple question but I am unable to find the answer to it. So in my Sails app I have a User model and I am trying to make a boolean field with a default value to be False.

Is there a way to specify defaults like some kind of default attribute etc??

I want something like this:

is_admin: {
        type: 'boolean',
        default: 'false'
    }

Thanks for your time.

Rajan Sharma
  • 2,211
  • 3
  • 21
  • 33
Gagandeep Singh
  • 316
  • 1
  • 4
  • 8

2 Answers2

26

use defaultsTo look this Waterline Docs

chridam
  • 100,957
  • 23
  • 236
  • 235
zieglar
  • 830
  • 8
  • 10
  • Be careful! In Mongo the default value is not set on objects older than the field it added a default value. For example if you added a 'locale' field to user model, after you already had some users, the old users will not be added a default locale value. only new users will have it. – Stas Arshanski Aug 08 '17 at 09:48
5

To use a contextual example of "defaultsTo" as described in Zieglar's answer

is_admin : {
    type : "boolean",
    defaultsTo : false
}
Charlie
  • 81
  • 1
  • 4