Javascript 使用Mongoose在对象数组中存储对象

Javascript 使用Mongoose在对象数组中存储对象,javascript,arrays,node.js,mongoose,mean-stack,Javascript,Arrays,Node.js,Mongoose,Mean Stack,我试图在mongoose中将几个注释对象推送到我的UserSchema中。但是,每当我运行这段代码时,它只为每个注释条目创建“_id”字段,即 我的模式: var mongoose = require('mongoose'); var Schema = mongoose.Schema; var CommentSchema = new Schema({ comments: { score: Number, body: String

我试图在mongoose中将几个注释对象推送到我的UserSchema中。但是,每当我运行这段代码时,它只为每个注释条目创建“_id”字段,即

我的模式:

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var CommentSchema = new Schema({
    comments: {
            score: Number,
            body: String
            }
});

var UserSchema = new Schema({
    username: {type: String, unique: true},
    comments: [CommentSchema]
}, { collection: 'user'});

module.exports = mongoose.model('User', UserSchema);
当然,我有更多的属性,但我只是包含了一个片段,以表明即使是一个小示例也不起作用。

由于我如何声明CommentSchema,调用中还有一个额外的“注释”。现在已经很明显了

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var CommentSchema = new Schema({
    comments: {
            score: Number,
            body: String
            }
});

var UserSchema = new Schema({
    username: {type: String, unique: true},
    comments: [CommentSchema]
}, { collection: 'user'});

module.exports = mongoose.model('User', UserSchema);