diff --git a/src/Jenssegers/Mongodb/Query/Builder.php b/src/Jenssegers/Mongodb/Query/Builder.php index c7383bbe2..549e2b57f 100644 --- a/src/Jenssegers/Mongodb/Query/Builder.php +++ b/src/Jenssegers/Mongodb/Query/Builder.php @@ -11,7 +11,6 @@ use Illuminate\Support\LazyCollection; use Illuminate\Support\Str; use Jenssegers\Mongodb\Connection; -use MongoCollection; use MongoDB\BSON\Binary; use MongoDB\BSON\ObjectID; use MongoDB\BSON\Regex; @@ -26,7 +25,7 @@ class Builder extends BaseBuilder { /** * The database collection. - * @var MongoCollection + * @var \MongoDB\Collection */ protected $collection; @@ -725,15 +724,11 @@ public function from($collection, $as = null) /** * @inheritdoc */ - public function truncate() + public function truncate(): bool { - $options = [ - 'typeMap' => ['root' => 'object', 'document' => 'object'], - ]; - - $result = $this->collection->drop($options); + $result = $this->collection->deleteMany([]); - return (1 == (int) $result->ok); + return (1 === (int) $result->isAcknowledged()); } /** diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 9f751fb88..ed2bb100c 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -176,8 +176,10 @@ public function testDelete() public function testTruncate() { DB::collection('users')->insert(['name' => 'John Doe']); + DB::collection('users')->insert(['name' => 'John Doe']); + $this->assertEquals(2, DB::collection('users')->count()); $result = DB::collection('users')->truncate(); - $this->assertEquals(1, $result); + $this->assertTrue($result); $this->assertEquals(0, DB::collection('users')->count()); }