我是mongodb和mongoose的新人。我想知道我是否可以创建一个包含两个子文档的数组,如果我愿意,只插入子文档中,如何访问子文档?
var User = mongoose.Schema({
username: String,
password: String,
UserToken: String,
//here is what I want to do
messagesArray: {
FromUserid: String,
messege: String
}
});
答案 0 :(得分:2)
你只需要使用[]
var User = mongoose.Schema({
username: String,
password: String,
UserToken: String,
messagesArray: [{
FromUserid: String,
messege: String
}]
});
查看mongoose,http://mongoosejs.com/docs/schematypes.html
接受的所有数据类型