import { Schema } from 'mongoose';
interface BinData {
type: number;
data: Buffer | string;
}
const mySchema = new Schema({
myField: {
type: Schema.Types.Mixed,
validate: {
validator: function (v: number | BinData) {
return typeof v === 'number' || (typeof v === 'object' && v !== null && 'type' in v && 'data' in v);
},
message: props => `${props.value} is not a valid value for myField`
}
}
});
1条答案
按热度按时间xv8emn3q1#