使用 mongoose 保存子文档数组创建空数组 MEAN 堆栈

sub document array saving using mongoose creates empty array MEAN stack

我对 mongo db 和 mongoose 很陌生。尝试使用子文档数组保存架构时遇到问题。子文档保存为空白。 我尝试在网上阅读许多解决方案,但无法 find/identify 合适的解决方案,因为我对此还很陌生。

这是我的 schema js 和 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);
        })
    });
}

提前致谢!!

怎么样:

const AppEntitySchema1 = new Schema({
    name : {type:String, unique:true},
    appName: String,
    entries : [{
        value : String,
        synonyms:[{
          type: String
      }]
    }]
});