我想验证子文档以检查它是否属于其中一个模式,即字符串的枚举之类的子单词,但对于子文档模式,是否可以在猫鼬中使用?
const mongoose = require("mongoose");
const metadataSchema = require("../schemas/metadataSchema");
const sizeSchema = require("../schemas/sizeSchema");
const fieldMaskSchema = require("../schemas/fieldMaskSchema");
const singlePageDocumentSchema = require("./singlePageDocumentSchema");
const twoSideDocumentSchema = require("./twoSideDocumentSchema");
const topBottomDocumentSchema = require("./topBottomDocumentSchema");
const templateSchema = new mongoose.Schema({
id: {
type: String,
required: true
},
metadata: metadataSchema,
pageSize: {
type: sizeSchema,
required: true
},
fieldMasks: [fieldMaskSchema],
// TODO validation for pages
pages: Should be one of [singlePageDocumentSchema, twoSideDocumentSchema, topBottomDocumentSchema]
});
module.exports = templateSchema;
当子文档应该是三种类型之一时,也许还有其他方法可以实现这种行为?