This is the Mongoose Schema:
var userschema = new mongoose.Schema({
user: String,
imagen: [{
tags: [String],
}]
});
I'm getting the tags with this:
var bodytags = req.body.tags;
var tags = tbags.split(" ");
I get the tags from req.body, and put all of them within an array. But the problems comes here:
var img = usermodel.findOne({ user: req.session.user }, function(err, user){
var img = user.imagen.push({
tags: undefined
});
});
img.tags.push(tags);
And when, I received an error that sais TypeError: Cannot call method 'push' of undefined. How can I push my array of tags inside the tags' array of my Schema?
Thank's advance!
EDITED:
And this would be the result of what I want:
{
user: randomuser,
imagen: [{
tags: ["one", "two", "three"
}]
}
And, if for example, there are two imagen objects:
{
user: randomuser,
imagen: [{
tags: ["one", "two", "three"]
},
{
tags: ["four", "five", "six"]
}]
}