I have a Mongoose schema defined as
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var userSchema = new Schema({
user_id: String,
event_organizer: [String],
});
module.exports = mongoose.model('User',userSchema);
Now, I have a function where I wish to add this User's Id to an event. Ofcourse, this event is already present in the DB.
function addUserToEvent(user_id, event_id) {
}
How do I add an event_id
to the user's event_organizer
array as defined in the schema?
It is possible that the array is already populated and I need to append the id, not reset it.
via Solly
No comments:
Post a Comment