Reputation: 533
I'm new with mongodb and mongoose. I want to know if I can make an array with two sub-documents and insert only in sub-documents if I want to and how can I access the sub doc?
var User = mongoose.Schema({
username: String,
password: String,
UserToken: String,
//here is what I want to do
messagesArray: {
FromUserid: String,
messege: String
}
});
Upvotes: 0
Views: 57
Reputation: 3464
you just have to wrap the messagesArray with a []
var User = mongoose.Schema({
username: String,
password: String,
UserToken: String,
messagesArray: [{
FromUserid: String,
messege: String
}]
});
See all the data types accepted by mongoose, http://mongoosejs.com/docs/schematypes.html
Upvotes: 2