77class Builder extends \Illuminate \Database \Query \Builder {
88
99 /**
10- * The database collection
11- *
12- * @var MongoCollection
13- */
10+ * The database collection
11+ *
12+ * @var MongoCollection
13+ */
1414 protected $ collection ;
1515
1616 /**
17- * All of the available operators.
18- *
19- * @var array
20- */
17+ * All of the available operators.
18+ *
19+ * @var array
20+ */
2121 protected $ conversion = array (
2222 '= ' => '= ' ,
2323 '!= ' => '$ne ' ,
@@ -29,11 +29,11 @@ class Builder extends \Illuminate\Database\Query\Builder {
2929 );
3030
3131 /**
32- * Create a new query builder instance.
33- *
34- * @param Connection $connection
35- * @return void
36- */
32+ * Create a new query builder instance.
33+ *
34+ * @param Connection $connection
35+ * @return void
36+ */
3737 public function __construct (Connection $ connection )
3838 {
3939 $ this ->connection = $ connection ;
@@ -339,24 +339,15 @@ public function update(array $values, array $options = array())
339339 */
340340 public function increment ($ column , $ amount = 1 , array $ extra = array ())
341341 {
342- // build update statement
343- $ update = array (
342+ $ query = array (
344343 '$inc ' => array ($ column => $ amount ),
345344 '$set ' => $ extra ,
346345 );
347346
348- // protect
347+ // Protect
349348 $ this ->whereNotNull ($ column );
350349
351- // perform
352- $ result = $ this ->collection ->update ($ this ->compileWheres (), $ update , array ('multiple ' => true ));
353-
354- if (1 == (int ) $ result ['ok ' ])
355- {
356- return $ result ['n ' ];
357- }
358-
359- return 0 ;
350+ return $ this ->performUpdate ($ query );
360351 }
361352
362353 /**
@@ -505,6 +496,28 @@ public function pull($column, $value = null)
505496 return $ this ->performUpdate ($ query );
506497 }
507498
499+ /**
500+ * Remove one or more fields.
501+ *
502+ * @param mixed $columns
503+ * @return int
504+ */
505+ public function dropColumn ($ columns )
506+ {
507+ if (!is_array ($ columns )) $ columns = array ($ columns );
508+
509+ $ fields = array ();
510+
511+ foreach ($ columns as $ column )
512+ {
513+ $ fields [$ column ] = 1 ;
514+ }
515+
516+ $ query = array ('$unset ' => $ fields );
517+
518+ return $ this ->performUpdate ($ query );
519+ }
520+
508521 /**
509522 * Get a new instance of the query builder.
510523 *
@@ -516,7 +529,7 @@ public function newQuery()
516529 }
517530
518531 /**
519- * Perform update.
532+ * Perform an update query .
520533 *
521534 * @param array $query
522535 * @param array $options
@@ -541,7 +554,7 @@ protected function performUpdate($query, array $options = array())
541554 }
542555
543556 /**
544- * Convert a key to MongoID if needed
557+ * Convert a key to MongoID if needed.
545558 *
546559 * @param mixed $id
547560 * @return mixed
@@ -557,10 +570,10 @@ protected function convertKey($id)
557570 }
558571
559572 /**
560- * Compile the where array
561- *
562- * @return array
563- */
573+ * Compile the where array.
574+ *
575+ * @return array
576+ */
564577 protected function compileWheres ()
565578 {
566579 if (!$ this ->wheres ) return array ();
@@ -694,4 +707,21 @@ protected function compileWhereRaw($where)
694707 return $ where ['sql ' ];
695708 }
696709
710+ /**
711+ * Handle dynamic method calls into the method.
712+ *
713+ * @param string $method
714+ * @param array $parameters
715+ * @return mixed
716+ */
717+ public function __call ($ method , $ parameters )
718+ {
719+ if ($ method == 'unset ' )
720+ {
721+ return call_user_func_array (array ($ this , 'dropColumn ' ), $ parameters );
722+ }
723+
724+ return parent ::__call ($ method , $ parameters );
725+ }
726+
697727}
0 commit comments