How it can be possible create sub-document with multi schema validation ?

31 views
Skip to first unread message

Sina

unread,
Jan 18, 2015, 5:50:42 PM1/18/15
to mongoo...@googlegroups.com
hello , 
I want to implement a validation on sub-document with two or more specific types , 
It should support validations
It is better support updating subdocs with doc functions too
I don't know what is the best implementation for adding this feature , with plugins , custom validations ,custom types or ...

var typeOne = new Schema({
    info
:String,
    message
:String
})

var typeTwo = new Schema({
    url
:String,
    names
:[String]
})

var itemSchema = new Schema({
    authorId
: { type:ObjectId, required:true, ref : 'user' },
    authorType
: { type:String, required:true, enum:userTypes },
    detail
:  {},//no any validation here
    itemType
: {type:String,required:true,enum:itemTypes}
})
var itemSchema = new Schema({
    authorId
: { type:ObjectId, required:true, ref : 'user' },
    authorType
: { type:String, required:true, enum:userTypes },
    detail
:  {type:[typeOne,typeTwo]},//I prefere it can be like this
    itemType
: {type:String,required:true,enum:itemTypes}
})

Reply all
Reply to author
Forward
0 new messages