File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ MongoDB for XP Framework ChangeLog
33
44## ?.?.? / ????-??-??
55
6- * Added new method ` Collection::count () ` to count documents in a collection
6+ * Added new methods ` Collection::distinct () ` and ` Collection:: count() `
77 (@thekid )
88* Added new method ` Collection::aggregate() ` to perform aggregations, see
99 https://docs.mongodb.com/manual/reference/command/aggregate/ and
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ public function find($filter= []): Cursor {
8989 * Count documents in this collection
9090 *
9191 * @param [:var] $filter
92- * @return com.mongodb.result.Cursor
92+ * @return int
9393 */
9494 public function count ($ filter = []): int {
9595 $ result = $ this ->proto ->msg (0 , 0 , [
@@ -100,6 +100,23 @@ public function count($filter= []): int {
100100 return $ result ['body ' ]['n ' ];
101101 }
102102
103+ /**
104+ * Returns distinct list of keys in this collection
105+ *
106+ * @param string $key
107+ * @param [:var] $filter
108+ * @return var[]
109+ */
110+ public function distinct ($ key , $ filter = []): array {
111+ $ result = $ this ->proto ->msg (0 , 0 , [
112+ 'distinct ' => $ this ->name ,
113+ 'key ' => $ key ,
114+ 'query ' => $ filter ?: (object )[],
115+ '$db ' => $ this ->database ,
116+ ]);
117+ return $ result ['body ' ]['values ' ];
118+ }
119+
103120 /**
104121 * Perfom aggregation over documents this collection
105122 *
You can’t perform that action at this time.
0 commit comments