Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeremyIglehart/d7ead4fcc86babe5f867515998a6eb95 to your computer and use it in GitHub Desktop.
Save JeremyIglehart/d7ead4fcc86babe5f867515998a6eb95 to your computer and use it in GitHub Desktop.
Response to comment on a stackoverflow question

Response to comment on a stackoverflow question

@David Weldon: Thank you for your response. I reset the project, and this time instead of running that update from my browser, I ran it right within the fixtures.js (which is obviously run from the server on startup). I am happier with how things are going into mongo on this reset, but I still can't read my subdocument - it's as if I'm not updating them properly. I feel like they are not there at all.

Here is the relevant fixture.js content:

// The "elvesEpisodetwoId" is set above in the file, I didn't include it because we are not experiencing problems with that collection at all and I'm pretty sure my client would like me to keep some level of privacy as much as possible for the code.

// Add Filler Idea Posts for Elves of Our Lord
var elvesEpisodeTwoIdeaOneId = Ideas.insert({
  title: "Jump through the portal",
  body: "The elves from Eldernland should jump through the blue portal mentioned in episode one.",
  userId: nate._id,
  author: nate.profile.name,
  episodeId: elvesEpisodetwoId,
  timestamp: new Date(now - 5 * 3600 * 1000),
  score: [],
  overallScore: 0,
  votedOnBy: [],
  timesVotedOn: 0
});

var elvesEpisodeTwoIdeaTwoId = Ideas.insert({
  title: "Go back to find your brother",
  body: "Travel north again to find your brother at black mountain.",
  userId: jeremy._id,
  author: jeremy.profile.name,
  episodeId: elvesEpisodetwoId,
  timestamp: new Date(now - 5 * 3600 * 1000),
  score: [],
  overallScore: 0,
  votedOnBy: [],
  timesVotedOn: 0
});

var elvesEpisodeTwoIdeaThreeId = Ideas.insert({
  title: "Revive Randolf With Bloodmagic",
  body: "Bring Randolf back from the dead using witche's bloodmagic.",
  userId: iryna._id,
  author: iryna.profile.name,
  episodeId: elvesEpisodetwoId,
  timestamp: new Date(now - 5 * 3600 * 1000),
  score: [],
  overallScore: 0,
  votedOnBy: [],
  timesVotedOn: 0
});

// Add Filler Votes
var nateVoteOne = Votes.insert({
  episodeId: elvesEpisodetwoId,
  userId: nate._id,
  timestamp: new Date(now - 5 * 3600 * 1000),
  winner: elvesEpisodeTwoIdeaOneId,
  loser: elvesEpisodeTwoIdeaTwoId
});

Ideas.update(elvesEpisodeTwoIdeaOneId, {
  $addToSet: {
    score: { userId: nate._id, score: 1 },
    votedOnBy: nate._id
  },
  $inc: {
    overallScore: 1,
    timesVotedOn: 1
  }
});

Here is the output from the console when running $ meteor mongo:

$ meteor mongo
MongoDB shell version: 2.6.7
connecting to: 127.0.0.1:3001/meteor
meteor:PRIMARY> use meteor
switched to db meteor
meteor:PRIMARY> db.ideas.find();
{
	"_id" : "kTkMpJDQHvW6BY5Fa",
	"title" : "Jump through the portal",
	"body" : "The elves from Eldernland should jump through the blue portal mentioned in episode one.",
	"userId" : "aLMkwf4Q6fdrcCsWy",
	"author" : "Nate Beck",
	"episodeId" : "CDpgoiL44JTQ6tts3",
	"timestamp" : ISODate("2016-06-08T16:45:33.369Z"),
	"score" : [
		{
			
		}
	],
	"overallScore" : 1,
	"votedOnBy" : [
		"aLMkwf4Q6fdrcCsWy"
	],
	"timesVotedOn" : 1
}
{
	"_id" : "jszQSPbReuaH9cxv8",
	"title" : "Go back to find your brother",
	"body" : "Travel north again to find your brother at black mountain.",
	"userId" : "uXWWB7E8Pw7bAQFfs",
	"author" : "Jeremy Iglehart",
	"episodeId" : "CDpgoiL44JTQ6tts3",
	"timestamp" : ISODate("2016-06-08T16:45:33.369Z"),
	"score" : [ ],
	"overallScore" : 0,
	"votedOnBy" : [ ],
	"timesVotedOn" : 0
}
{
	"_id" : "t3kGTvCx5W7Pb2uwx",
	"title" : "Revive Randolf With Bloodmagic",
	"body" : "Bring Randolf back from the dead using witche's bloodmagic.",
	"userId" : "WYLmH49ptjZHTy8J5",
	"author" : "Iryna Iglehart",
	"episodeId" : "CDpgoiL44JTQ6tts3",
	"timestamp" : ISODate("2016-06-08T16:45:33.369Z"),
	"score" : [ ],
	"overallScore" : 0,
	"votedOnBy" : [ ],
	"timesVotedOn" : 0
}
meteor:PRIMARY> db.ideas.findOne({_id:"kTkMpJDQHvW6BY5Fa"}).score;
[ { } ]

Conclusion:

This to me feels like I'm not doing the "update" correctly (starting at line 58 of this gist). Because it feels like the document never makes it there. Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment