0

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);
        })
    });
}

Output : Thanks in advance!!

Krishna Kiriti
  • 83
  • 2
  • 10

1 Answers1

0

How about doing this:

const AppEntitySchema1 = new Schema({
    name : {type:String, unique:true},
    appName: String,
    entries : [{
        value : String,
        synonyms:[{
          type: String
      }]
    }]
});
Quirinux
  • 310
  • 2
  • 7
  • actually i changed it to synonyms : [String] , of course what you suggested is also same. It's working fine. Thank you dude – Krishna Kiriti Oct 09 '17 at 13:43