Ticket Get Comments

Thanks @canelacho. It passed :blush:

Good to hear that! :metal:

This is my code, it passes sort, but not “can fetch comments for a movie” :
const pipeline = [
{
$match: {
_id: ObjectId(id)
},
},
{
lookup: { from: 'comments', let: {"id": "_id"},
pipeline: [
{
$match: {
$expr: {
$eq: ["$movie_id", “$$id”]
}
}
},
{
$sort: {
“date”: -1
}
}
],
as: “comments”
}
}

  ]

I honestly cannot tell what is wrong, It looks exactly like other code that people are posting and saying has passed.

What am I missing here?

I don’t know why, but it is removing the $ from lookup when I post it here. The $lookup is in my code

@erictenenbaum, I got the same like yours, pass the comments should be sorted by date , but not the other one.

I took a closer look at the tests, and I’m not passing “Once Upon a Time in Mexico” should have 2 comments, but it shows up as 0. Then I checked my atlas cluster in compass and it doesn’t show any comments for that movie. I do a simple find by movie_id in the comments collection and nothing shows up. Has anyone else had this issue? I am fairly certain the code actually works because when I console logged the movie variable in the test case the comments section shows up as an empty array.

Did this happen to anyone?

All up there have kinda similar & accurate code but i dont know why but $sort is not working in code but in campus same pipeline is working properly with sort.
people who have done already, help

I think i’m about ready to throw in the towel on this course. I moved on to the next ticket create/update comment, I changed up the code just slightly for console logging to:
static async addComment(movieId, user, comment, date) {
try {

  // TODO Ticket: Create/Update Comments
  // Construct the comment document to be inserted into MongoDB.
  const commentDoc = { movie_id: movieId, name: user.name, email: user.email, text: comment, date: date }
  const createdComment = await await comments.insertOne(commentDoc)
  console.log("created comment: ", createdComment.ops)
  return createdComment
} catch (e) {
  console.error(`Unable to post comment: ${e}`)
  return { error: e }
}

}

This is what I get in the console:

console.log src/dao/commentsDAO.js:51
created comment: [ { movie_id: ‘573a13eff29313caabdd82f3’,
name: ‘foobar’,
email: ‘foobar@baz.com’,
text: ‘fe-fi-fo-fum’,
date: 2019-02-25T04:59:49.184Z,
_id: 5c7376455822a1508028ec33 } ]

yet somehow I am still not passing “can post a comment”

To quote an all time classic, I feel like I am taking crazy pills here!!

@ erictenenbaum
first delete the double await in the line 4 in your example ok or better, delete that line.
Then wrap the “movieId” value in the ObjectId() imported. I hope you understand what I say, if not, check the deleteOne for better understand.
Finally fix the return. return await comments.insertOne(commentDoc).
What do you expect to get if you are modifying all the code unnecessarily?

Like wtf, why is this even in the “can post a comment” test?!
const martianComments = (await MoviesDAO.getMovieByID(movieId)).comments

expect(martianComments[0]._id).toEqual(postCommentResult.insertedId)
expect(martianComments[0].text).toEqual(comment.text)

How is this even testing a comment being posted?!

Please read the existing threads before creating or continuing to post on just the most recent topic.

This was a summary given nearly two days ago:

And that was largely in order to collect the various pointers accumulated from the preceding week of posts in itself.

There are 50 posts on this thread, and the majority of them say very little and more than half are posting code against the forum guidelines.

This has all been answered before. Please take the time to read the existing responses before asking the same things over and over again.

I’m sorry, I didn’t read the guidelines beforehand. I should have… Not being able to post your code makes it kind of difficult to ask/answer questions though. I kinda figured this forum would be more or less a stackOverflow for this course. Sorry!

I’m still frustrated the getComments isn’t working, I kinda went off on a tangent about the create/update comments because I ended up moving on, but that issue is related to this thread and I’m still not seeing what I’m doing wrong. I watched that video like 10 times and I feel like my code is the exact same, swapping count for sort

1 Like

in StackOverflow you find someone who help you with solutions, here you can find some people who wants to help others giving them some hints to get an idea and solve the tickets.
We must respect the forum guidelines :sunglasses:

People often think that have to do a lot of code but that isn’t the reality, The course is very simple, you only have to do short modifications in a few or one line in the project and that’s it. Simple and Easy.

This right here is what I was missing, the document as should be named “comments” I thought it could be anything I wanted, lol.

1 Like

Hello @erictenenbaum,

I noticed about two errors in your code, first of check your initialization on the variable let: {…}, the dollar sign is missing. Secondly, your const pipeline = , should be renamed differently from the inner pipeline: [ {$match: <…>}], then be sure to to also use the correct value on your: return await aggregate(<>).next().

While I agree that the task is indeed worded, I believe it would be better (and easier) for us to work on the task by just adding part of the instructions in the comments of the code. In this case, it’s just another short line of comment. A suggestion for the instructors of the course.

I would like to think that everyone here is a software developer of some sort, including students at higher institutions. Discourse is a powerful tool where your code can be displayed as a code block and there is even a preview on the right side of the text editor. I find it very difficult to help those who do not bother to display their code properly. I guess this is how the instructors feel as well. If you don’t make it easy for others to help you, then don’t expect your questions to be replied to.

1 Like

Here is my code
const pipeline = [
{
$match: { _id: ObjectId(id) }
},
{
lookup: { from:'comments', let: { 'id': '_id’ },
pipeline: [
{
‘$match’: {’$expr’: { ‘$eq’: [’$movie_id’, ‘$$id’ ] } }
},
{
‘$sort’: { ‘date’: -1 }
}
],
as: ‘comments’
}
}
]

But sort is not working