Fatal error: class "MongoDate" was not found when using mongodb php driver 1.1.2 and PHP 7.0.2 - Laravel 5.1

I am trying to configure MongoDB to work with my Laravel 5.1 Homestead instance on an Ubuntu 14.04 virtual machine. I was able to successfully install the latest version of MongoDB, which supports PHP 7.0 using sudo pecl install mongodb(this is correct for 7.0, not sudo pecl install mongo).

Then I added the extension to my php.ini files (all three) on my Ubuntu computer, each of which:

  • /etc/php/7.0/cli/php.ini
  • /etc/php/7.0/fpm/php.ini
  • /etc/php/7.0/cgi/php.ini

This is the extension I wrote that is correct for use with PHP 7.0:

  • extension=mongodb.so (not more than mongo.so)

When I run phpinfo()in my browser, it indicates that MongoDB is configured correctly with my PHP 7.0.

If MongoDB is configured correctly, why do I keep getting:

Fatal error: Class 'MongoDate' not found

php artisan migrate:refresh --seed?

:

  • Ubuntu vagrant reload vagrant reload --provision
  • PHP Nginx sudo service nginx restart sudo service php7.0-fpm restart

.

+4
2

, Mongo PHP 7.

, ..

MongoClient MongoDB\Driver\Manager

MongoDate MongoDB\BSON\UTCDateTime

, , !

+13

unix MongoDate. :

new MongoDate(strtotime('-1 day'));

, unix MongoDB\BSON\UTCDateTime,

<?php

class MongoHelper {

    const SECONDS_IN_A_MILLISECOND = 1000;

    public static function getMongoUTCDateTimeFromUnixTimestamp($timestamp) {
        return new \MongoDB\BSON\UTCDateTime(intval($timestamp * self::SECONDS_IN_A_MILLISECOND));
    }

    public static function getUnixTimestampFromMongoUTCDateTime(\MongoDB\BSON\UTCDateTime $utc_date_time) {
        return intval((string) $utc_date_time / self::SECONDS_IN_A_MILLISECOND);
    }
}

:

MongoHelper::getMongoUTCDateTimeFromUnixTimestamp(strtotime('-1 day'));
+4

Source: https://habr.com/ru/post/1623360/


All Articles