-
Notifications
You must be signed in to change notification settings - Fork 7
Add python solutions to CRUD workshop challenges #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add python solutions to CRUD workshop challenges #32
Conversation
dfreniche
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, but some changes are needed, please review. Thanks!
Jibola
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking comments. Things look 100% from dbx-python side.
|
@dfreniche Hi Diego, |
dfreniche
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| "as": "reviews" | ||
| } | ||
| } | ||
| ]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AfiMaameDufie this code is not working correctly. The foreignField should be where the book id field is in the reviews collection. In this case, it is in bookId. Also, we're missing a loop to print out the results. My proposed code is:
books_with_reviews = books.aggregate([
{
"$lookup":
{
"from": "reviews",
"localField": "_id",
"foreignField": "bookId",
"as": "reviews"
}
},
// use this stage to filter only books that have reviews
{
"$match": {
"reviews.0": { "$exists": True }
}
}
])
for book in books_with_reviews:
title = book.get('title')
reviews = book.get('reviews')
print(f"Book Title: {title} - Reviews: {reviews}")Thoughts?
I added the python solutions to the CRUD operations lab.