SchemaObjectId
SchemaObjectId()
SchemaObjectId.checkRequired()
SchemaObjectId.get()
SchemaObjectId.get()
SchemaObjectId.prototype.auto()
SchemaObjectId.prototype.checkRequired()
SchemaObjectId.schemaName
SchemaObjectId.set()
SchemaObjectId()
パラメータ
key
«文字列»オプション
«オブジェクト»
継承
ObjectId スキーマタイプコンストラクタ。
SchemaObjectId.checkRequired()
パラメータ
fn
«関数»
返り値
- «関数»
型
- «プロパティ»
required
チェックに文字列を渡すかどうかを確認するために使用される、必須バリデータ関数をオーバーライドします。
例
// Allow empty strings to pass `required` check
mongoose.Schema.Types.String.checkRequired(v => v != null);
const M = mongoose.model({ str: { type: String, required: true } });
new M({ str: '' }).validateSync(); // `null`, validation passes!
SchemaObjectId.get()
パラメータ
getter
«関数»
返り値
- «this»
型
- «プロパティ»
すべての ObjectId インスタンスにゲッターをアタッチします
例
// Always convert to string when getting an ObjectId
mongoose.ObjectId.get(v => v.toString());
const Model = mongoose.model('Test', new Schema({}));
typeof (new Model({})._id); // 'string'
SchemaObjectId.get()
パラメータ
caster
«関数»
返り値
- «関数»
型
- «プロパティ»
任意の値をオブジェクト ID にキャストするために使用される関数を取得/設定します。
例
// Make Mongoose only try to cast length 24 strings. By default, any 12
// char string is a valid ObjectId.
const original = mongoose.ObjectId.cast();
mongoose.ObjectId.cast(v => {
assert.ok(typeof v !== 'string' || v.length === 24);
return original(v);
});
// Or disable casting entirely
mongoose.ObjectId.cast(false);
SchemaObjectId.prototype.auto()
パラメータ
turnOn
«ブール値» 自動生成される ObjectId の既定値
返り値
- «SchemaType» this
turnOn が true の場合に、自動生成された ObjectId 既定値を追加します。
SchemaObjectId.prototype.checkRequired()
パラメータ
value
«任意の»doc
«Document»
返り値
- «ブール値»
指定された値が必須のバリデータを満たしているかどうかを確認します。
SchemaObjectId.schemaName
型
- «プロパティ»
このスキーマタイプの名前であり、関数名を変更する難読化ツールからの防御に使用されます。
SchemaObjectId.set()
パラメータ
option
«文字列» 値を設定するオプションvalue
«任意の» オプションの値
返り値
- «未定義、void»
型
- «プロパティ»
すべての ObjectId インスタンスの既定のオプションを設定します。
例
// Make all object ids have option `required` equal to true.
mongoose.Schema.ObjectId.set('required', true);
const Order = mongoose.model('Order', new Schema({ userId: ObjectId }));
new Order({ }).validateSync().errors.userId.message; // Path `userId` is required.