mongoose schema object array arbitrary size code example
Example 1: js array of strings mongoose
var personSchema = new mongoose.Schema({
tags: [{
type: String
}]
Example 2: define maxmum size of schema field in nodejs
db.createCollection("people", {
validator: {
$jsonSchema: {
bsonType: "object",
required: [ "name" ],
properties: {
name: {
bsonType: ["string"],
description: "must be a string"
},
friends: {
bsonType: ["array"],
items : { bsonType: ["string"] },
minItems: 0,
maxItems: 10,
description: "must be a array of string and max is 10"
}
}
}
}
});