John
John

Reputation: 533

Mongoose array document

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

Answers (1)

stalin
stalin

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

Related Questions