File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ MongoDB for XP Framework ChangeLog
33
44## ?.?.? / ????-??-??
55
6+ * Added new method ` Collection::count() ` to count documents in a collection
7+ (@thekid )
68* Added new method ` Collection::aggregate() ` to perform aggregations, see
79 https://docs.mongodb.com/manual/reference/command/aggregate/ and
810 https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/
Original file line number Diff line number Diff line change @@ -85,6 +85,21 @@ public function find($filter= []): Cursor {
8585 return new Cursor ($ this ->proto , $ result ['body ' ]['cursor ' ]);
8686 }
8787
88+ /**
89+ * Count documents in this collection
90+ *
91+ * @param [:var] $filter
92+ * @return com.mongodb.result.Cursor
93+ */
94+ public function count ($ filter = []): int {
95+ $ result = $ this ->proto ->msg (0 , 0 , [
96+ 'count ' => $ this ->name ,
97+ 'query ' => $ filter ?: (object )[],
98+ '$db ' => $ this ->database ,
99+ ]);
100+ return $ result ['body ' ]['n ' ];
101+ }
102+
88103 /**
89104 * Perfom aggregation over documents this collection
90105 *
You can’t perform that action at this time.
0 commit comments