I'd like to build an up a 'topic' object in my Meteor app's User.profile property. Here is what I have so far:
Template.addToReviewList.events({
'submit form': function(theEvent) {
theEvent.preventDefault();
var selectedTopic = Session.get('selectedTopic');
Meteor.users.update({_id:Meteor.user()._id}, {$set: {'profile.topics': selectedTopic}});
}
});
This works as expected creating something like User.profile.topics: math. If I select a new topic and run it again my topic gets updated accordingly. Again this is expected.
I'd like to build a 'topic' object so that each time the function runs, it results in something like this:
User.profile.topics: { topic1: true, topic2: true, topic3: true,...}
I've tired every combination of string concating the User.profile.topics I can think of and none of them work. Here is one example:
Template.addToReviewList.events({
'submit form': function(theEvent) {
theEvent.preventDefault();
var selectedTopic = Session.get('selectedTopic');
Meteor.users.update({_id:Meteor.user()._id}, {$set: {'profile.topics.'+selectedTopic: true}});
}
});
Am I not escaping something properly? Do I need to use a different Mongo Field operator? Something else?
Thanks in advance.