Type validation of DBRef result #4

Closed
jessesanford opened this Issue Jun 30, 2011 · 2 comments

2 participants

@jessesanford

Is there any way to inform the DBRef field on the parent object of the type of the document that is at the other end of the reference? Maybe via the defaults or some other means?

Mission = new Schema({

  user : {type: DBRef, default: {type: User}}

})

It would be helpful to know that the DBRef is pointing to the correct document type

@goulash1971
Owner

I've pushed a change which allows you to specify a namespace validation which will check to see that the namespace of the DBRef is a specific value:

Mission = new Schema({
    user : {type: DBRef, ns: 'users'}
})

Or one of a number of values:

Mission = new Schema({
    user : {type: DBRef, ns: ['users', 'roles']}
})

Or matches a filter function:

Mission = new Schema({
    user : {type: DBRef, ns: function (ns) { return ns.startsWith ('com.'); }}
})
@jessesanford
@goulash1971 goulash1971 closed this Jul 2, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment