Pila
Pila

Reputation: 5852

class 'MongoDB\Cient' not found

I am using the following code to create a connection to a MongoDB server, so as to create databases and stuff but I keep getting class 'MongoDB\Cient' not found. I really need help.

<?php 
    $client = new MongoDB\Client('mongodb://localhost:27017');
    $db = $client->reach;
    $collection = $db->messages;
    $collection->insertOne($record);
?>

where $record is some record.

Also, $mng = new MongoDB\Driver\Manager("mongodb://localhost:27017"); connects and I can use it to communicated with any already created db (using the command line). So, I want to ask if MongoDB\Driver\Manager can substitute MongoDB\Client?

Upvotes: 2

Views: 248

Answers (1)

Pila
Pila

Reputation: 5852

After all the struggle, this solved the issue...

installing using composer:

$ composer require "mongodb/mongodb=^1.0.0"
OUTPUT:
    ./composer.json has been created
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Installing mongodb/mongodb (1.0.0)
    Downloading: 100%         

Writing lock file
Generating autoload files

Usage:

<?php
require 'vendor/autoload.php'; // include Composer goodies

$client = new MongoDB\Client("mongodb://localhost:27017");
$collection = $client->demo->beers;

$result = $collection->insertOne( [ 'name' => 'Hinterland', 'brewery' => 'BrewDog' ] );

echo "Inserted with Object ID '{$result->getInsertedId()}'";
?>

That fixed the issue for me. follow the link:

http://docs.php.net/manual/en/mongodb.tutorial.library.php

Upvotes: 2

Related Questions