From: Louis-Vincent Boudreault Date: Fri, 16 Aug 2019 13:56:36 +0000 (-0400) Subject: mongodb: Fixed failing test for `aggregate` method. X-Git-Url: http://nitlanguage.org 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 --- 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