Arrays of schema types in Mongoose

I have a diagram:

var s = new Schema({ links: { type: [Url] } }); 

In this case, I am using the URL scheme type from https://github.com/bnoguchi/mongoose-types - but I have tried this with other types. Mongoose doesn't seem to check / use the schema type when in an array - works fine without an array.

How can I define an array of schema types that will check?

+4
source share
2 answers

From the developer Mongoose:

.

"If the URL is not a subdocument, the check will not get triggered at present (there is a ticket to open somewhere to support a richer type) Processing around to determine the check on the array: https://gist.github.com/aheckmann/12f9ad103e0378db6afc "

I ended up creating subdocuments, since Mongoose supports checking them in array form.

 var links = new Schema({ link: URL }); var s = new Schema({ links: { type: [links] } }); 
+9
source

Try var s = new Schema({links: [Url]});

0
source

All Articles