Skip to content

Instantly share code, notes, and snippets.

@JustAyush
Created June 20, 2019 14:42
Show Gist options
  • Save JustAyush/0ac23bec265c1047130a28bd717ebc8b to your computer and use it in GitHub Desktop.
Save JustAyush/0ac23bec265c1047130a28bd717ebc8b to your computer and use it in GitHub Desktop.
x=mycol.aggregate([{"$match":{"average_rating":{"$gt":4}}},{"$sort":{"average_rating":-1}},{"$limit":50},{"$sample":{"size":15}}])
top_rated_books=list(x)
top_rated =mycol.aggregate([{"$match":{"ISBN":{"$in":top_rated_books}}},
{"$project":{'_id':0, 'ISBN':'$ISBN', 'genres': '$genres', 'bookTitle': '$Book-Title', 'bookAuthor': '$Book-Author', 'publicationYear': '$Year-Of-Publication', 'publisher': '$Publisher', 'imageURL': '$Image-URL', 'averageRating': '$average_rating', 'description': '$description', 'publicationYear':'$publication_year'} }])
print(top_rated)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment