File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,31 @@ function find(array $filter = array(), array $options = array()) {
7878 return $ cursor ;
7979 }
8080
81+ /**
82+ * Performs a find (query) on the collection, returning at most one result
83+ *
84+ * @see http://docs.mongodb.org/manual/core/read-operations-introduction/
85+ * @see MongoDB\Collection::getFindOptions() for supported $options
86+ *
87+ * @param array $filter The find query to execute
88+ * @param array $options Additional options
89+ * @return array|false The matched document, or false on failure
90+ */
91+ function findOne (array $ filter = array (), array $ options = array ()) {
92+ $ options = array_merge ($ this ->getFindOptions (), array ("limit " => 1 ), $ options );
93+
94+ $ query = $ this ->_buildQuery ($ filter , $ options );
95+
96+ $ cursor = $ this ->manager ->executeQuery ($ this ->ns , $ query , $ this ->rp );
97+
98+ $ array = iterator_to_array ($ cursor );
99+ if ($ array ) {
100+ return $ array [0 ];
101+ }
102+
103+ return false ;
104+ }
105+
81106 /**
82107 * Retrieves all find options with their default values.
83108 *
You can’t perform that action at this time.
0 commit comments