I am creating simple RestApi using MongoDB, Mongoose, Node.js, Express.js and In which there will be multiple users and many more users can sign up and there will be an entry for each user in user collection(database). And my user Schema(users.js) will be like
var mongoSchema = mongoose.Schema;
var userSchema ={
mobileno: {
type:String
},
firstname: {
type:String
},
lastname: {
type:String
},
facebookid: {
type:String
},
userimage: {
type:String
}
}
module.exports = mongoose.model('user', userSchema);
Now each user can save one or more products as follows
Now which one would be the best solution:
- Should I use separate collection (products collection with one field like mobile no for reference)
- Or Should I use subdocument or nested objects
My personal choice is second one but I am new in MongoDB and Mongoose environment. Please help me what I need to change in users schema.