File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 58
58
foreach ($ result as $ document ) {
59
59
var_dump ($ document );
60
60
}
61
+ $ result = $ collection ->distinct ("citizen " );
62
+ echo "Distinct countries: \n" ;
63
+ var_dump ($ result );
61
64
62
65
$ result = $ collection ->updateMany (
63
66
array ("citizen " => "Iceland " ),
Original file line number Diff line number Diff line change @@ -264,6 +264,32 @@ function getCountOptions() { /* {{{ */
264
264
);
265
265
} /* }}} */
266
266
267
+ function distinct ($ fieldName , array $ filter = array (), array $ options = array ()) { /* {{{ */
268
+ $ options = array_merge ($ this ->getFindOptions (), $ options );
269
+ $ cmd = array (
270
+ "distinct " => $ this ->collname ,
271
+ "key " => $ fieldName ,
272
+ "query " => $ filter ,
273
+ $ options
274
+ );
275
+
276
+ $ doc = $ this ->_runCommand ($ this ->dbname , $ cmd )->getResponseDocument ();
277
+ if ($ doc ["ok " ]) {
278
+ return $ doc ["values " ];
279
+ }
280
+ throw $ this ->_generateCommandException ($ doc );
281
+ } /* }}} */
282
+ function getDistinctOptions () { /* {{{ */
283
+ return array (
284
+ /**
285
+ * The maximum amount of time to allow the query to run. The default is infinite.
286
+ *
287
+ * @see http://docs.mongodb.org/manual/reference/command/distinct/
288
+ */
289
+ "maxTimeMS " => 0 ,
290
+ );
291
+ } /* }}} */
292
+
267
293
protected function _generateCommandException ($ doc ) { /* {{{ */
268
294
if ($ doc ["errmsg " ]) {
269
295
return new Exception ($ doc ["errmsg " ]);
You can’t perform that action at this time.
0 commit comments