From 8be048e22d937c87ac37e9214654847e092663bd Mon Sep 17 00:00:00 2001 From: Louis-Vincent Boudreault Date: Fri, 16 Aug 2019 09:56:36 -0400 Subject: [PATCH] mongodb: Fixed failing test for `aggregate` method. The test assumed the query would return in some order when it is not. Added a "$sort" stage to the pipeline to avoid miss index asserts. Signed-off-by: Louis-Vincent Boudreault --- lib/mongodb/mongodb.nit | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/mongodb/mongodb.nit b/lib/mongodb/mongodb.nit index 020e0ce..7db69e7 100644 --- a/lib/mongodb/mongodb.nit +++ b/lib/mongodb/mongodb.nit @@ -640,11 +640,12 @@ class MongoCollection # # var res = col.aggregate("""[ # { "$match": { "status": "A" } }, - # { "$group": { "_id": "$cust_id", "total": { "$sum": "$amount" } } } + # { "$group": { "_id": "$cust_id", "total": { "$sum": "$amount" } } }, + # { "$sort" : { "_id": 1 } } # ]""".parse_json.as(JsonArray)) # - # assert res[0].to_json == """{"_id":"B212","total":200}""" - # assert res[1].to_json == """{"_id":"A123","total":750}""" + # assert res[0].to_json == """{"_id":"A123","total":750}""" + # assert res[1].to_json == """{"_id":"B212","total":200}""" # ~~~ fun aggregate(pipeline: JsonArray): Array[JsonObject] do var q = new JsonObject -- 1.7.9.5