Chapter 2 : Lab 1: I got the answer but is it the right solution?

I would like to discuss this after dead line passes.

Hi,

Just checked the result and I believe it is correct. Let’s wait after the deadline to discuss the answer.

José Carlos

1 Like

Hello Jose,

I am working on the lab “Using Cursor like Stages”, and have created a pipeline, but looks like I am missing some operator, as the title for 25th record is listed as “Tar Creek”. I really struggled with null arrays after the setIntersection operator[o/p var: castFavs] .

In the post, I read that someone has used ifNull, and used the same approach to check for null & used the size operator on castFav array to calculate the num of favorites. After mentioning the sort order, I am using limit to check the title of 25th record. Not sure why I am not getting the correct title ? I am specifying the pipeline below for your review.

Thanks,
Jeetan

db.movies.aggregate([{
$match: {
movies released in the USA with a tomatoes.viewer.rating greater than or equal to 3,
documents with cast array using elemMatch
}, {
$addFields: {
apply map operator to remove extraneous chars after (,
favorite array,
intersection of cast & fav
}, {
$project: {
title: 1,
countries: 1,
“tomatoes.viewer.rating”: 1,
num_fav: {
$size: {
$ifNull: ["$castFavs", [{
value: 0
}]]
}
}
}
}, {
$sort: {
num_fav: -1,
“tomatoes.viewer.rating”: -1,
title: -1
}
}, {
$limit: 25
}])

Carlos - As specified in the optional exercise in the previous lab. I added the $elemMatch to check for cast array, and use $map to remove any extras in the name, and then later added another filter to check for num
_fav $gte 1, to remove null after fav intersect & ifNull operator, and then with $limit as 25, I am finding a record a different record but still not from one of the option. Please suggest & I am hoping that previous pipeline is not in the forum, as I tried to send it for your review.

Hi,

I reached you via email so that you can send your query.

José Carlos

Thanks for your reply. Please find query in the attached file.

Regards,

Jeetan

(Attachment M121_Ch2_Lab1 is missing)

Attached .txt for easy reference.

(Attachment M121_Ch2_Lab1.txt is missing)