I am very new to node.js and REST in general. My model has following schema:
"properties": {
"name": {
"type": "string",
"description": "student name"
},
"family": {
"type": "string",
"description": "family name"
},
"subjects": {
"type": "array",
"description": "list of subjects taken",
"minItems": 1,
"items": { "type": "string" },
"uniqueItems": true
}
First two properties are straight forward as they are string. But I am confused how to post an array for subjects. I have coded the model like this:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var StudentSchema = new Schema({
name: String,
family: String,
subject: [String]
});
module.exports = mongoose.model('Student', StudentSchema);
I don't know whether I have made it correct or not. When I tried to POST using POSTMAN, it persisted the record, but I don't know whether it was stored as an array or String only. How do I verify that? How do I add a validation that length of the array has to be >1 for persisting?