I am very new to mongo db and mongoose. I am having a problem when tried to save schema with sub document arrays. Sub documents are saved as blanks. I tried reading many solutions in the net but couldn't find/identify the suitable one as I am pretty new to this.
here is my code snippet of schema js and router js,
schema.js
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const AppEntitySchema1 = new Schema({
name : {type:String, unique:true},
appName: String,
entries : [{
value : String,
synonyms:[{String}]
}]
});
const AppEntitySchema = mongoose.model('entity',AppEntitySchema1);
module.exports = AppEntitySchema;
router.js
// load the Entity model
var Entity = require('../models/entity');
// expose the routes to our app with module.exports
module.exports = function(app) {
// create entity and send back all entities after creation
app.post('/api/entities', function(req, res) {
let model = new Entity(req.body);
model.save(function(err,createdObject){
if(err){
res.send(err);
return;
}
res.send(createdObject);
})
});
}