I need help with integrating user prompts into my social networking site. I want to gather responses in an array and then insert the entire array at once into a MongoDB database. While I am able to prompt users, I am facing challenges when it comes to inserting the array. Below is the code snippet:
'click #creator': function(event){
var channelName = prompt('Enter The Channel Name');
var howmany = +prompt('How many people do you want? (max 10)');
var users = [];
var arr = []; // define our array
if(howmany > 1 && howmany<10){
for (var i = 0; i < howmany; i++) { // loop 10 times
arr.push(prompt('Enter a user' + (i+1))); // push the value into the array
}
users = arr.join('"," ');
Meteor.call('addChannel', channelName, users);
}
}
Here is the insertion piece of the code:
Channels = new Mongo.Collection('channels');
Meteor.methods({
addChannel: function(channelName, users){
if(!Meteor.userId()) {
throw new Meteor.Error('not-authorized', 'you are not signed in');
}
var username = Meteor.user().username;
Channels.insert({
name: channelName,
created: new Date(),
members: $push: {users}
createdBy: username
});
},
});