shashwat yadav
shashwat yadav

Reputation: 11

MongoDB with php fails to create collection

It shows the following error and no new collections are created in the mlab database.

Connected
( ! ) Notice: Undefined property: MongoDB\Driver\Manager::$helfis in C:\wamp\www\mongo.php on line 11
Database mydb selected
( ! ) Fatal error: Call to a member function createCollection() on a non-object in > C:\wamp\www\mongo.php on line 13

Here's my PHP Code:

<?php

    $m = new MongoDB\Driver\Manager("mongo_url");

    echo "Connected";

    $db = $m->helfis;
    echo "Database mydb selected";
    $collection = $db->createCollection("myhell");
    echo "Collection created succsessfully";

    $collection = $db->dashboard;
    echo "Collection selected succsessfully";

?>

Upvotes: 0

Views: 991

Answers (1)

Sujith Tharanga
Sujith Tharanga

Reputation: 11

    $command = new MongoDB\Driver\Command(["create" => 'testcollection']);

    $cursor = $this->mgoManagerObj->executeCommand("testdb", $command);
    $response = $cursor->toArray()[0];
    var_dump($response);

Upvotes: 1

Related Questions