@@ -18,6 +18,13 @@ class Builder extends \Illuminate\Database\Query\Builder {
1818 */
1919 protected $ collection ;
2020
21+ /**
22+ * The column projections.
23+ *
24+ * @var array
25+ */
26+ public $ projections ;
27+
2128 /**
2229 * All of the available clause operators.
2330 *
@@ -59,6 +66,19 @@ public function __construct(Connection $connection)
5966 $ this ->connection = $ connection ;
6067 }
6168
69+ /**
70+ * Set the projections.
71+ *
72+ * @param array $columns
73+ * @return $this
74+ */
75+ public function project ($ columns )
76+ {
77+ $ this ->projections = is_array ($ columns ) ? $ columns : func_get_args ();
78+
79+ return $ this ;
80+ }
81+
6282 /**
6383 * Execute a query for a single record by ID.
6484 *
@@ -152,9 +172,10 @@ public function getFresh($columns = array())
152172 $ pipeline [] = array ('$group ' => $ group );
153173
154174 // Apply order and limit
155- if ($ this ->orders ) $ pipeline [] = array ('$sort ' => $ this ->orders );
156- if ($ this ->offset ) $ pipeline [] = array ('$skip ' => $ this ->offset );
157- if ($ this ->limit ) $ pipeline [] = array ('$limit ' => $ this ->limit );
175+ if ($ this ->orders ) $ pipeline [] = array ('$sort ' => $ this ->orders );
176+ if ($ this ->offset ) $ pipeline [] = array ('$skip ' => $ this ->offset );
177+ if ($ this ->limit ) $ pipeline [] = array ('$limit ' => $ this ->limit );
178+ if ($ this ->projections ) $ pipeline [] = array ('$project ' => $ this ->projections );
158179
159180 // Execute aggregation
160181 $ results = $ this ->collection ->aggregate ($ pipeline );
@@ -179,11 +200,19 @@ public function getFresh($columns = array())
179200 else
180201 {
181202 $ columns = array ();
203+
204+ // Convert select columns to simple projections.
182205 foreach ($ this ->columns as $ column )
183206 {
184207 $ columns [$ column ] = true ;
185208 }
186209
210+ // Add custom projections.
211+ if ($ this ->projections )
212+ {
213+ $ columns = array_merge ($ columns , $ this ->projections );
214+ }
215+
187216 // Execute query and get MongoCursor
188217 $ cursor = $ this ->collection ->find ($ wheres , $ columns );
189218
@@ -543,8 +572,6 @@ public function push($column, $value = null, $unique = false)
543572 */
544573 public function pull ($ column , $ value = null )
545574 {
546- var_dump ($ value );
547-
548575 // Check if we passed an associative array.
549576 $ multipleValues = (is_array ($ value ) and array_keys ($ value ) === range (0 , count ($ value ) - 1 ));
550577
0 commit comments