Working on my first planning poker tool using Meteor, I am navigating through meteor and json document stores for the first time. For user stories, I have set up a Collection which includes the users assigned to each story and their ratings.
To start off, I will be doing some inserts like this:
Stories.insert({'story': stories[i], 'assignees': users, 'ratings': []});
...and an entry would resemble something along these lines:
{
'story': 'some story',
'assignees': ['Bob', 'Joe'],
'ratings': []
}
Once a user has provided their rating for a particular story, it should be updated to display something like this:
{
'story': 'some story',
'assignees': ['Bob', 'Joe'],
'ratings': [{'Bob': 2}, {'Joe': 5}] // Is there perhaps a better way to structure this?
}
I am struggling with writing the code to achieve this. Currently, what I have is:
var users = ['Bob', 'Joe'];
for (var i = 0; i < users.length; i++) {
var user = users[i];
var rating = {user: 1};
Stories.update({}, {$push: {'ratings': rating}});
}
Regrettably, the outcome looks somewhat like this:
{
'story': 'some story',
'assignees': ['Bob', 'Joe'],
'ratings': [{user: 1}]
}
Only one object in the ratings
array, and the key is not even correct (it's just user
instead of e.g., Bob
). This issue might be related to JS hoisting and complexities in instantiating objects. Any feedback or advice would be greatly appreciated.