Merge: mongo::queries: add unwind method
authorJean Privat <jean@pryen.org>
Fri, 10 Feb 2017 16:00:00 +0000 (11:00 -0500)
committerJean Privat <jean@pryen.org>
Fri, 10 Feb 2017 16:00:00 +0000 (11:00 -0500)
Also fix `op` method so it matches the specification in the comment

Pull-Request: #2362

lib/mongodb/queries.nit

index 3c7b1cd..4b8e9a1 100644 (file)
@@ -87,7 +87,7 @@ class MongoMatch
                        q["${name}"] = value
                        self[field] = q
                else
-                       self[name] = value
+                       self["${name}"] = value
                end
                return self
        end
@@ -479,6 +479,20 @@ class MongoPipeline
        # { $group: { <group> } }
        # ~~~
        fun group(group: MongoGroup): MongoPipeline do return add_stage("group", group)
+
+       # Apply unwind
+       #
+       # https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/
+       #
+       # Deconstructs an array field from the input documents to output a document
+       # for each element.
+       # Each output document is the input document with the value of the array
+       # field replaced by the element.
+       #
+       # ~~~json
+       # { $unwind: <field path> }
+       # ~~~
+       fun unwind(path: String): MongoPipeline do return add_stage("unwind", path)
 end
 
 # Mongo pipeline group stage