SchemaBoolean


SchemaBoolean()

パラメーター
  • path «文字列»
  • options «オブジェクト»
継承

ブーリアン SchemaType のコンストラクタ


SchemaBoolean.checkRequired()

パラメーター
  • fn «関数»
戻り値
  • «関数»
タイプ
  • «プロパティ»

必須バリデータが、ブール値が required チェックに合格するかどうかをチェックするために使用する関数をオーバーライドします。


SchemaBoolean.convertToFalse

タイプ
  • «セット»

どの値が false にキャストされるかを設定します。

const M = mongoose.model('Test', new Schema({ b: Boolean }));
new M({ b: 'nay' }).b; // undefined
mongoose.Schema.Types.Boolean.convertToFalse.add('nay');
new M({ b: 'nay' }).b; // false

SchemaBoolean.convertToTrue

タイプ
  • «セット»

どの値が true にキャストされるかを設定します。

const M = mongoose.model('Test', new Schema({ b: Boolean }));
new M({ b: 'affirmative' }).b; // undefined
mongoose.Schema.Boolean.convertToTrue.add('affirmative');
new M({ b: 'affirmative' }).b; // true

SchemaBoolean.get()

パラメーター
  • getter «関数»
戻り値
  • «this»
タイプ
  • «プロパティ»

すべてのブール値インスタンスに getter をアタッチします

mongoose.Schema.Boolean.get(v => v === true ? 'yes' : 'no');

const Order = mongoose.model('Order', new Schema({ isPaid: Boolean }));
new Order({ isPaid: false }).isPaid; // 'no'

SchemaBoolean.get()

パラメーター
  • caster «関数»
戻り値
  • «関数»
タイプ
  • «プロパティ»

任意の値をブール値にキャストするために使用する関数を定義します。

// Make Mongoose cast empty string '' to false.
const original = mongoose.Schema.Boolean.cast();
mongoose.Schema.Boolean.cast(v => {
  if (v === '') {
    return false;
  }
  return original(v);
});

// Or disable casting entirely
mongoose.Schema.Boolean.cast(false);

SchemaBoolean.prototype.checkRequired()

パラメーター
  • value «任意»
戻り値
  • «ブール型»

指定された値が必須バリデータの条件を満たすかどうかをチェックします。ブール値が必須バリデータの条件を満たすには、完全に true または false でなければなりません。


SchemaBoolean.schemaName

タイプ
  • «プロパティ»

このスキーマタイプの名前。関数の名前を削減するminify攻撃に対する防御策です。


SchemaBoolean.set()

パラメーター
  • option «文字列» 値を設定するオプション

  • value «任意» オプションの値

戻り値
  • «未定義、無効»
タイプ
  • «プロパティ»

すべてのブール値インスタンスにデフォルトのオプションを設定します。

// Make all booleans have `default` of false.
mongoose.Schema.Boolean.set('default', false);

const Order = mongoose.model('Order', new Schema({ isPaid: Boolean }));
new Order({ }).isPaid; // false