How to perform drop() using MongoDB drivers for php 7?

后端 未结 1 865
梦毁少年i
梦毁少年i 2021-01-25 10:29

How to perform drop() or remove() and other functions by using MongoDB drivers for php 7?

I refered https://docs.mongodb.org/v3.0/reference/method/js-collection/

<
相关标签:
1条回答
  • 2021-01-25 10:57

    You can delete a collection like this:

    $manager = new \MongoDB\Driver\Manager("mongodb://" . $username . ":" . $password . "@{$host}:{$port}");
    $manager->executeCommand('database', new \MongoDB\Driver\Command(["drop" => "collection"]));
    

    or you could follow the instructions in this guide:

    $db = (new MongoDB\Client)->demo;
    
    $result = $db->dropCollection('users');
    var_dump($result);
    
    0 讨论(0)
提交回复
热议问题