SchemaBuffer


SchemaBuffer()

パラメータ
  • キー «文字列»
  • オプション «オブジェクト»
継承

バッファー SchemaType コンストラクター


SchemaBuffer.checkRequired()

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

文字列が必須チェックに合格するかどうかを確認するために必須バリデーターが使用する関数をオーバーライドします。

// Allow empty strings to pass `required` check
mongoose.Schema.Types.String.checkRequired(v => v != null);

const M = mongoose.model({ buf: { type: Buffer, required: true } });
new M({ buf: Buffer.from('') }).validateSync(); // validation passes!

SchemaBuffer.get()

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

すべてのバッファーインスタンスにゲッターをアタッチする

// Always convert to string when getting an ObjectId
mongoose.Schema.Types.Buffer.get(v => v.toString('hex'));

const Model = mongoose.model('Test', new Schema({ buf: Buffer } }));
typeof (new Model({ buf: Buffer.fromString('hello') }).buf); // 'string'

SchemaBuffer.prototype.checkRequired()

パラメータ
  • «任意»
  • ドキュメント «ドキュメント»
戻り値
  • «ブール値»

指定された値が必須バリデーターを満たすかどうかを確認します。必須バリデーターを満たすには、バッファーは null または undefined であってはならず、長さがゼロであってはなりません。


SchemaBuffer.prototype.subtype()

パラメータ
  • サプタイプ «数字» デフォルトのサプタイプ

戻り値
  • «SchemaType» これ

このバッファーのデフォルトのsubtypeを設定します。 こちらで許可されるサブタイプの リストを参照してください。

const s = new Schema({ uuid: { type: Buffer, subtype: 4 });
const M = db.model('M', s);
const m = new M({ uuid: 'test string' });
m.uuid._subtype; // 4

SchemaBuffer.schemaName

タイプ
  • «プロパティ»

関数の名前をあやふやにするミニファイアから防御するためのこのスキーマタイプの名前。


SchemaBuffer.set()

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

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

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

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

// Make all buffers have `required` of true by default.
mongoose.Schema.Buffer.set('required', true);

const User = mongoose.model('User', new Schema({ test: Buffer }));
new User({ }).validateSync().errors.test.message; // Path `test` is required.