gamnit: fix X position of first char of a TextSprites
[nit.git] / lib / mongodb / queries.nit
index 995a555..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
@@ -301,6 +301,50 @@ class MongoMatch
                op("nor", field, new JsonArray.from(expressions))
                return self
        end
+
+       # Array contains all
+       #
+       # https://docs.mongodb.com/manual/reference/operator/query/all/#op._S_all
+       #
+       # `$all` selects the documents where the value of a field is an array that
+       # contains all the specified elements.
+       #
+       # ~~~json
+       # { field: { $all: [ <value1>, <value2>, ... ] } }
+       # ~~~
+       fun all(field: nullable String, values: Array[Jsonable]): MongoMatch do
+               op("all", field, new JsonArray.from(values))
+               return self
+       end
+
+       # Array element match
+       #
+       # https://docs.mongodb.com/manual/reference/operator/query/elemMatch/#op._S_elemMatch
+       #
+       # `$elemMatch` matches documents that contain an array field with at least
+       # one element that matches all the specified query criteria.
+       #
+       # ~~~json
+       # { field: { $elemMatch: <query> } }
+       # ~~~
+       fun elem_match(field: nullable String, query: Jsonable): MongoMatch do
+               op("elemMatch", field, query)
+               return self
+       end
+
+       # Array size match
+       #
+       # https://docs.mongodb.com/manual/reference/operator/query/size/#op._S_size
+       #
+       # `$size` matches any array with the number of elements specified by the argument
+       #
+       # ~~~json
+       # { field: { $size: <size> } }
+       # ~~~
+       fun size(field: nullable String, size: Int): MongoMatch do
+               op("size", field, size)
+               return self
+       end
 end
 
 # Mongo pipelines are arrays of aggregation stages
@@ -435,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