From f5448504030b40d5fb198bc14baea7168bda65a4 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 1 Feb 2023 16:02:52 +0100 Subject: [PATCH] Fix MongoDB queries --- unimore_bda_6/database.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/unimore_bda_6/database.py b/unimore_bda_6/database.py index d4bcd6c..593ef71 100644 --- a/unimore_bda_6/database.py +++ b/unimore_bda_6/database.py @@ -58,7 +58,7 @@ def sample_reviews_by_rating(reviews: pymongo.collection.Collection, rating: flo """ return reviews.aggregate([ - {"$filter": {"overall": rating}}, + {"$match": {"overall": rating}}, {"$sample": {"size": amount}}, ]) @@ -69,7 +69,14 @@ def sample_reviews_by_rating_polar(reviews: pymongo.collection.Collection, amoun """ return reviews.aggregate([ - {"$filter": {"overall": {"$or": [1.0, 5.0]}}}, + {"$match": + {"$or": + [ + {"overall": 1.0}, + {"overall": 5.0}, + ] + }, + }, {"$sample": {"size": amount}}, ])