Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to validate object structure? #5997

Closed
artofspeed opened this issue Jan 14, 2018 · 2 comments
Closed

how to validate object structure? #5997

artofspeed opened this issue Jan 14, 2018 · 2 comments

Comments

@artofspeed
Copy link

I want the the property "localized_words" to be an object mapping string to array.

With the following code, I can only ensure it's an Object, but how can I ensure the values are strictly array?

var schema = mongoose.Schema({
   // example
   // this should fail   : { en: [], fr: 123 }
   // this should succeed: { en: [], fr: []  }
   // but with current code, any object will pass validation
   localized_words : { type: Object }
});
@sobafuchs
Copy link
Contributor

sobafuchs commented Jan 15, 2018

You can do that like this:

var schema = new mongoose.Schema({
   localized_words : [String]
});

@vkarpov15
Copy link
Collaborator

Duplicate of #681 and a bunch of other issues, please follow #681 for updates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants