File tree 2 files changed +7
-10
lines changed
src/Jenssegers/Mongodb/Query
2 files changed +7
-10
lines changed Original file line number Diff line number Diff line change 11
11
use Illuminate \Support \LazyCollection ;
12
12
use Illuminate \Support \Str ;
13
13
use Jenssegers \Mongodb \Connection ;
14
- use MongoCollection ;
15
14
use MongoDB \BSON \Binary ;
16
15
use MongoDB \BSON \ObjectID ;
17
16
use MongoDB \BSON \Regex ;
@@ -26,7 +25,7 @@ class Builder extends BaseBuilder
26
25
{
27
26
/**
28
27
* The database collection.
29
- * @var MongoCollection
28
+ * @var \MongoDB\Collection
30
29
*/
31
30
protected $ collection ;
32
31
@@ -725,15 +724,11 @@ public function from($collection, $as = null)
725
724
/**
726
725
* @inheritdoc
727
726
*/
728
- public function truncate ()
727
+ public function truncate (): bool
729
728
{
730
- $ options = [
731
- 'typeMap ' => ['root ' => 'object ' , 'document ' => 'object ' ],
732
- ];
733
-
734
- $ result = $ this ->collection ->drop ($ options );
729
+ $ result = $ this ->collection ->deleteMany ([]);
735
730
736
- return (1 == (int ) $ result ->ok );
731
+ return (1 === (int ) $ result ->isAcknowledged () );
737
732
}
738
733
739
734
/**
Original file line number Diff line number Diff line change @@ -176,8 +176,10 @@ public function testDelete()
176
176
public function testTruncate ()
177
177
{
178
178
DB ::collection ('users ' )->insert (['name ' => 'John Doe ' ]);
179
+ DB ::collection ('users ' )->insert (['name ' => 'John Doe ' ]);
180
+ $ this ->assertEquals (2 , DB ::collection ('users ' )->count ());
179
181
$ result = DB ::collection ('users ' )->truncate ();
180
- $ this ->assertEquals ( 1 , $ result );
182
+ $ this ->assertTrue ( $ result );
181
183
$ this ->assertEquals (0 , DB ::collection ('users ' )->count ());
182
184
}
183
185
You can’t perform that action at this time.
0 commit comments