File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 136
136
echo "Kasparov \n" ;
137
137
var_dump ($ result );
138
138
139
+ echo "Deleting him, he isn't Croatian just yet \n" ;
140
+ $ result = $ collection ->findOneAndDelete (array ("citizen " => "Croatia " ));
141
+ var_dump ($ result );
142
+
143
+ echo "This should be empty \n" ;
144
+ $ result = $ collection ->find (array ());
145
+ foreach ($ result as $ document ) {
146
+ var_dump ($ document );
147
+ }
139
148
} catch (Exception $ e ) {
140
149
printf ("Caught exception '%s', on line %d \n" , $ e ->getMessage (), __LINE__ );
141
150
exit ;
Original file line number Diff line number Diff line change @@ -368,6 +368,46 @@ protected function _massageAggregateOptions($options) { /* {{{ */
368
368
} /* }}} */
369
369
370
370
/* {{{ findAndModify */
371
+ function findOneAndDelete (array $ filter , array $ options = array ()) { /* {{{ */
372
+ $ options = array_merge ($ this ->getFindOneAndDeleteOptions (), $ options );
373
+ $ options = $ this ->_massageFindAndModifyOptions ($ options );
374
+ $ cmd = array (
375
+ "findandmodify " => $ this ->collname ,
376
+ "query " => $ filter ,
377
+ ) + $ options ;
378
+
379
+ $ doc = $ this ->_runCommand ($ this ->dbname , $ cmd )->getResponseDocument ();
380
+ if ($ doc ["ok " ]) {
381
+ return $ doc ["value " ];
382
+ }
383
+
384
+ throw $ this ->_generateCommandException ($ doc );
385
+ } /* }}} */
386
+ function getFindOneAndDeleteOptions () { /* {{{ */
387
+ return array (
388
+
389
+ /**
390
+ * The maximum amount of time to allow the query to run.
391
+ *
392
+ * @see http://docs.mongodb.org/manual/reference/command/findAndModify/
393
+ */
394
+ "maxTimeMS " => 0 ,
395
+
396
+ /**
397
+ * Limits the fields to return for all matching documents.
398
+ *
399
+ * @see http://docs.mongodb.org/manual/tutorial/project-fields-from-query-results
400
+ */
401
+ "projection " => array (),
402
+
403
+ /**
404
+ * Determines which document the operation modifies if the query selects multiple documents.
405
+ *
406
+ * @see http://docs.mongodb.org/manual/reference/command/findAndModify/
407
+ */
408
+ "sort " => array (),
409
+ );
410
+ } /* }}} */
371
411
372
412
function findOneAndReplace (array $ filter , array $ replacement , array $ options = array ()) { /* {{{ */
373
413
if (key ($ replacement )[0 ] == '$ ' ) {
You can’t perform that action at this time.
0 commit comments