mongodb: Fixed failing test for `aggregate` method.
authorLouis-Vincent Boudreault <lv.boudreault95@gmail.com>
Fri, 16 Aug 2019 13:56:36 +0000 (09:56 -0400)
committerLouis-Vincent Boudreault <lv.boudreault95@gmail.com>
Fri, 16 Aug 2019 13:56:36 +0000 (09:56 -0400)
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 <lv.boudreault95@gmail.com>

lib/mongodb/mongodb.nit

index 020e0ce..7db69e7 100644 (file)
@@ -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