Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Type validation of DBRef result #4

therealjessesanford opened this Issue · 2 comments

2 participants

Jesse Sanford Stuart Hudson
Jesse Sanford

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

Stuart Hudson

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.'); }}
Jesse Sanford
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.