Code Monkey home page Code Monkey logo

mongo-php-driver's Introduction

MongoDB PHP Driver

Tests Coverage Status Coding Standards

This extension is developed atop the libmongoc and libbson libraries. It provides a minimal API for core driver functionality: commands, queries, writes, connection management, and BSON serialization.

Userland PHP libraries that depend on this extension may provide higher level APIs, such as query builders, individual command helper methods, and GridFS. Application developers should consider using this extension in conjunction with the MongoDB PHP library, which implements the same higher level APIs found in MongoDB drivers for other languages.

Documentation

Installation

To build and install the driver:

$ pecl install mongodb
$ echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`

Additional installation instructions may be found in the PHP.net documentation.

This extension is intended to be used alongside the MongoDB PHP Library, which is distributed as the mongodb/mongodb package for Composer.

Release Integrity

Releases are created automatically and signed using the PHP team's GPG key. This applies to the git tag as well as all release packages provided as part of a GitHub release. To verify the provided packages, download the key and import it using gpg:

gpg --import php-driver.asc

PECL package

PECL packages are made available as release artifacts on GitHub, as well as on the PECL homepage. The GitHub release will also contain a detached signature file for the PECL package (named mongodb-X.Y.Z.tgz.sig).

To verify the integrity of the downloaded package, run the following command:

gpg --verify mongodb-X.Y.Z.tgz.sig mongodb-X.Y.Z.tgz

Note

No verification is done when using pecl to install the package. To ensure release integrity when using pecl, download the tarball manually from the GitHub release, verify the signature, then install the package from the downloaded tarball using pecl install mongodb-X.Y.Z.tgz.

Windows

Windows binaries distributed through GitHub releases contain a detached signature for the php_mongodb.dll file named php_mongodb.dll.sig. To verify the integrity of the DLL, run the following command:

gpg --verify php_mongodb.dll.sig php_mongodb.dll.tgz

Note

Windows binaries distributed directly through PECL are not signed by MongoDB and cannot be verified. If you need to verify the integrity of the downloaded binary, always download them from the GitHub release.

Reporting Issues

Issues pertaining to the extension should be reported in the PHPC project in MongoDB's JIRA. Library-related issues should be reported in the PHPLIB project.

For general questions and support requests, please use one of MongoDB's Technical Support channels.

Security Vulnerabilities

If you've identified a security vulnerability in a driver or any other MongoDB project, please report it according to the instructions in Create a Vulnerability Report.

Development

Development is tracked in the PHPC project in MongoDB's JIRA. Documentation for contributing to this project may be found in CONTRIBUTING.md.

mongo-php-driver's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mongo-php-driver's Issues

undefined symbol: _mongoc_sasl_set_service_host

Building version without option, or with --with-openssl-dir=/usr --with-mongodb-sasl=/usr

$ php  -d extension=modules/mongodb.so -v
PHP Warning:  PHP Startup: Unable to load dynamic library 'modules/mongodb.so' - modules/mongodb.so: undefined symbol: _mongoc_sasl_set_service_host in Unknown on line 0
PHP 5.6.7 (cli) (built: Mar 19 2015 13:50:28) 
...

phpsize errors

I get the following errors when running phpsize.
/usr/bin/m4:config.m4:429: cannot open src/libmongoc/build/autotools/m4/ax_pthr ead.m4': No such file or directory /usr/bin/m4:config.m4:463: cannot opensrc/libbson/build/autotools/CheckAtomics .m4': No such file or directory
/usr/bin/m4:config.m4:464: cannot open src/libbson/build/autotools/FindDependen cies.m4': No such file or directory /usr/bin/m4:config.m4:465: cannot opensrc/libbson/build/autotools/m4/ac_compil e_check_sizeof.m4': No such file or directory
/usr/bin/m4:config.m4:466: cannot open src/libbson/build/autotools/m4/ac_create _stdint_h.m4': No such file or directory /usr/bin/m4:config.m4:508: cannot opensrc/libmongoc/build/autotools/Versions.m 4': No such file or directory
/usr/bin/m4:config.m4:523: cannot open `src/libbson/build/autotools/Versions.m4' : No such file or directory
autom4te: /usr/bin/m4 failed with exit status: 1

update("$push") does not work with Persistable

I have document structure similar to that:
class A { /** @var B[] */ private $_b = []; }
Both A and B are persistable. So, when I insert A with multiple Bs via driver, it's OK. I see __pclass field in mongo shell.
When I execute something like (of course, again via php api)
update({"$push": {"b": {new B object}}})
no __pclass field is created and unserialization goes wrong.

Failing to build from source (PHP 5.6.15 + mongo-php-driver 1.0.0)

Hi guys, first of all, thanks for such a great piece of work, I've been using it for a while now.

I've always built the driver from sources but I'm having a few problems lately:

/usr/bin/m4:ext/mongo/config.m4:429: cannot open 'src/libmongoc/build/autotools/m4/ax_pthread.m4': No such file or directory
/usr/bin/m4:ext/mongo/config.m4:463: cannot open 'src/libbson/build/autotools/CheckAtomics.m4': No such file or directory
/usr/bin/m4:ext/mongo/config.m4:464: cannot open 'src/libbson/build/autotools/FindDependencies.m4': No such file or directory
/usr/bin/m4:ext/mongo/config.m4:465: cannot open 'src/libbson/build/autotools/m4/ac_compile_check_sizeof.m4': No such file or directory
/usr/bin/m4:ext/mongo/config.m4:466: cannot open 'src/libbson/build/autotools/m4/ac_create_stdint_h.m4': No such file or directory
/usr/bin/m4:ext/mongo/config.m4:508: cannot open 'src/libmongoc/build/autotools/Versions.m4': No such file or directory
/usr/bin/m4:ext/mongo/config.m4:523: cannot open 'src/libbson/build/autotools/Versions.m4': No such file or directory
autom4te: /usr/bin/m4 failed with exit status: 1
rebuilding main/php_config.h.in
/usr/bin/m4:ext/mongo/config.m4:429: cannot open 'src/libmongoc/build/autotools/m4/ax_pthread.m4': No such file or directory
/usr/bin/m4:ext/mongo/config.m4:463: cannot open 'src/libbson/build/autotools/CheckAtomics.m4': No such file or directory
/usr/bin/m4:ext/mongo/config.m4:464: cannot open 'src/libbson/build/autotools/FindDependencies.m4': No such file or directory
/usr/bin/m4:ext/mongo/config.m4:465: cannot open 'src/libbson/build/autotools/m4/ac_compile_check_sizeof.m4': No such file or directory
/usr/bin/m4:ext/mongo/config.m4:466: cannot open 'src/libbson/build/autotools/m4/ac_create_stdint_h.m4': No such file or directory
/usr/bin/m4:ext/mongo/config.m4:508: cannot open 'src/libmongoc/build/autotools/Versions.m4': No such file or directory
/usr/bin/m4:ext/mongo/config.m4:523: cannot open 'src/libbson/build/autotools/Versions.m4': No such file or directory

These are the flags I'm using: --enable-mongo=shared --with-libmongoc --with-libbson (along with a few others).

And this is how I clone the repository:

git clone [email protected]:mongodb/mongo-php-driver.git -b master mongo
cd mongo
git submodule init
git submodule update

cd src/libbson
./autogen.sh
cd ../libmongoc
./autogen.sh

Can you spot anything wrong? Should I provide any additional detail?

Thanks in advance!

PS: I've checked and all files exists, apparently is a relative path issue with m4_include inside ext/mongo/config.m4.

Cannot find OpenSSL's libraries when I try to install

sudo pecl install mongodb-beta
...
checking configuring libmongoc... ...
checking Use system libmongoc... no
checking for pkg-config... no
configure: error: Cannot find OpenSSL's libraries

I've tried with/without sudo. I've tried to just install the mongodb lib without the -beta. I have all the openssl libs and dev libs installed and it still gives me this message. I'm using ubuntu utopic

Cannot $set an int64

Initially with the old mongo driver, you could only save Int32 and the extra bits would get truncated. Eventually a runtime configuration mongo.native_long was added which would enable the use of Int64. I can't speak for other platforms, but with my current setup trying to do [$set => ["TestInt" => 4294967295]] will save an Int32 in the database with value -1 (so it wraps around instead of truncating). I've tried using the same runtime configuration from the old driver but it does not appear to have any effect with mongodb driver.

Similarly, there does not appear to be a MongoInt32/MongoInt64 equivalent within the MongoDB\BSON namespace. I could probably write my own little MongoInt32/MongoInt64 classes in PHP that implement MongoDB\BSON\Serializable and MongoDB\BSON\Unserializable, but it definitely feels like something that's missing in native.

It's worth noting that reading an Int64 from the database seems to work nicely (at least on 64-bit platforms).

Windows 7, 64-bit
Apache 2.4.18, 64-bit TS
PHP 7.0.2, 64-bit TS
Mongo 3.2.0
MongoDB driver 1.1.1

Having Problem with $collection->remove($criteria)

I am using XAMPP with Windows 7. I am using array("name"=>"Learn more PHP") for the criteria. I am not using any options. I have no problem deleting a document with the Mongo shell using the equivalent criteria. I also have no problem with queries or inserting documents using PHP.

Building for OS X and homebrew

Hello, I trying to make missing Homebrew (OS X package manager) package for PHP7, but I have some troubles with building extension from source.
When I run make -j6 all I see error mongo-php-driver-prototype/src/contrib/php-ssl.h:33:10: fatal error: 'openssl/evp.h' file not found. I have installed openssl in my system, but i don't know how to link openssl with this extension.
Maybe someone can help me with building this extension?
Thanks.

Compile error in src/bson.c on ARM/Raspian

On OSX all compiles well; CPP output:

#496 "/usr/local/src/mongo-php-driver-prototype/src/bson.c"
 return 0;
}
_Bool php_phongo_bson_visit_int64(const bson_iter_t *iter __attribute__ ((unused)), const char *key, int64_t v_int64, void *data)
{
 zval *retval = &((php_phongo_bson_state *)data)->zchild;
 add_assoc_long_ex(retval, key, strlen(key), v_int64);; 
 return 0;
}

On Linux 4.1.7-v7+ armv7l / Raspbian GNU/Linux 8.0 (jessie) the same code generates:

#496 "/var/local/src/mongo-php-driver-prototype/src/bson.c"
 return 0;
}

_Bool php_phongo_bson_visit_int64(const bson_iter_t *iter __attribute__ ((unused)), const char *key, int64_t v_int64, void *data)
{
 zval *retval = &((php_phongo_bson_state *)data)->zchild;

 if (v_int64 > 2147483647L || v_int64 < (-2147483647L - 1L)) { char *tmp; int tmp_len; mongoc_log(MONGOC_LOG_LEVEL_WARNING, "PHONGO-BSON", "Integer overflow detected on your platform: %lld", v_int64); tmp_len = spprintf(&tmp, 0, "%lld", v_int64); add_assoc_stringl; } else { add_assoc_long_ex(retval, key, strlen(key), v_int64); };

 return 0;
}

with the following errors:

/var/local/src/mongo-php-driver-prototype/src/bson.c: In function ‘php_phongo_bson_visit_int64’:
/var/local/src/mongo-php-driver-prototype/src/bson.c:508:38: error: macro "add_assoc_stringl" passed 5 arguments, but takes just 4
  ADD_ASSOC_INT64(retval, key, v_int64);
                                      ^
In file included from /var/local/src/mongo-php-driver-prototype/src/bson.c:38:0:
./phongo_compat.h:112:3: error: ‘add_assoc_stringl’ undeclared (first use in this function)
   add_assoc_stringl(zval, key, tmp, tmp_len, 0); \
   ^
/var/local/src/mongo-php-driver-prototype/src/bson.c:508:2: note: in expansion of macro ‘ADD_ASSOC_INT64’
  ADD_ASSOC_INT64(retval, key, v_int64);
  ^
./phongo_compat.h:112:3: note: each undeclared identifier is reported only once for each function it appears in
   add_assoc_stringl(zval, key, tmp, tmp_len, 0); \
   ^
/var/local/src/mongo-php-driver-prototype/src/bson.c:508:2: note: in expansion of macro ‘ADD_ASSOC_INT64’
  ADD_ASSOC_INT64(retval, key, v_int64);
  ^

Segmentation fault when creating Manager with empty arguments

When executing phpunit to instantiate a Manager, I am seeing a consistent segmentation fault error like this:

/usr/local/bin/phpunit: line 3:  2440 Segmentation fault: 11  /usr/bin/env php -d allow_url_fopen=On -d detect_unicode=Off /usr/local/Cellar/phpunit/5.0.0/libexec/phpunit-5.0.0.phar

when creating a Manager with these empty arguments:

$manager = new \MongoDB\Driver\Manager("mongodb://localhost:27017", [], []);

But after removing the empty [] arguments it works fine:

$manager = new \MongoDB\Driver\Manager("mongodb://localhost:27017");

This was found when I noticed MongoDB\Client passes in these default values.

Also perhaps related, I notice under when trying to access any method, like getServers(), I see this error:

Fatal error: Allowed memory size of 1828716544 bytes exhausted (tried to allocate 18446744073273022950 bytes) in /Users/jeremyjannotta/Documents/dev/projects/mongodb/vendor/mongodb/mongodb/src/Client.php on line 32

Call Stack:
    0.0006     230272   1. {main}() /Users/jeremyjannotta/Documents/dev/projects/mongodb/index.php:0
    0.0070     344288   2. MongoDB\Client->__construct() /Users/jeremyjannotta/Documents/dev/projects/mongodb/index.php:6
    0.0070     344576   3. MongoDB\Driver\Manager->__construct() /Users/jeremyjannotta/Documents/dev/projects/mongodb/vendor/mongodb/mongodb/src/Client.php:32

Executing this on Mac OSX 10.11.2, PHP 5.6.14, PHPUnit 5.0.0, MongoDB driver v1.1.0.

Segfault on 1.1.2 whenever running PHP

On Ubuntu 15.10 x64:

% sudo php5-fpm -t || echo "Exit status: $?"
[27-Jan-2016 01:35:47] NOTICE: configuration file /etc/php5/fpm/php-fpm.conf test is successful

Exit status: 139

Here's an excerpt from catchsegv:

Backtrace:
php5-fpm[0x6dee88]
/usr/lib/x86_64-linux-gnu/sasl2/libdigestmd5.so(+0x391b)[0x7f29ffd7491b]
/usr/lib/x86_64-linux-gnu/libsasl2.so.2(+0x6cc9)[0x7f2a07ba5cc9]
/usr/lib/x86_64-linux-gnu/libsasl2.so.2(sasl_client_done+0x2a)[0x7f2a07ba5e0a]
/usr/lib/php5/20131226/mongodb.so(+0x6122e)[0x7f2a003eb22e]
/lib/x86_64-linux-gnu/libpthread.so.0(+0xe36b)[0x7f2a0d3c036b]
/lib64/ld-linux-x86-64.so.2(+0x10bb7)[0x7f2a0fb96bb7]
/lib/x86_64-linux-gnu/libc.so.6(+0x39d32)[0x7f2a0d609d32]
/lib/x86_64-linux-gnu/libc.so.6(+0x39d85)[0x7f2a0d609d85]
php5-fpm(fpm_init+0x182)[0x7b9912]
php5-fpm(main+0x776)[0x465366]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f2a0d5f0a40]
php5-fpm(_start+0x29)[0x466539]

If I remove package libsasl2-dev before compiling, it works fine.

No suitable servers found - Windows, PHP 5.6 NTS - beta 1

Hello

I'm using new MongoDB\Driver\Manager("mongodb://localhost:27017");
I tested with the beta1 on windows with php 5.6 NTS(official dll build), but also with PHP7 in linux custom build(built by me from php7 branch).

I have the server locally for testing. It works with the old mongo extension on php 5.6.
I tried to enable debug with mongodb.debug but also mongodb.debug_log as in doc, but i get no debug info in logs

I use monogdb 3.0.6.

Any ideas what might be the problem ?

How to the value of _id field?

I use $.post method of jQuery to send a request and received the response, but the _id is empty like screen capture. How i get the value of _id or convert ObjectId to it's value in MongoDB? Thanks very much!
image
btw: How i format fields in MongoDB? e.g. format '20150901180116' to '2015-09-01 18:01:16'.

compiling on vagrant machine

hey guys,

i keep getting this error when i run make -j6 all in home/vagrant/mongo-php-driver-prototype/php_phongo.c

/home/vagrant/mongo-php-driver-prototype/php_phongo.c:222:7: warning: assignment from incompatible pointer type [enabled by default] dt = php_format_date((char *)"Y-m-d\\TH:i:sP", strlen("Y-m-d\\TH:i:sP"), t, 0 TSRMLS_CC);

sys info Linux vaprobash 3.13.0-62-generic #102-Ubuntu SMP Tue Aug 11 14:29:36 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Count Method

Is there a plan to implement the count method as it was in the previous pecl/mongo package?

Timeout problem

  1. The timeout has no exception message
  2. The timeout shouldn't occur

see the following tests scripts:

<?php

$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017');
$manager->executeCommand('mongotest', new MongoDB\Driver\Command(['dropDatabase' => 1]));

$bulk = new MongoDB\Driver\BulkWrite();
$bulk->insert(array(
    'x' => 1
));
$manager->executeBulkWrite('mongotest.test', $bulk);

sleep(1);

try {
    $bulk = new MongoDB\Driver\BulkWrite();
    $bulk->insert(array(
        'x' => 2
    ));
    $manager->executeBulkWrite('mongotest.test', $bulk);
} catch (\Exception $e) {
    var_dump($e->getMessage());
}

Second (legacy driver works as expected):

<?php

$client = new MongoClient('mongodb://localhost:27017');
$client->selectDB('mongotest')->drop();

$collection = $client->selectDB('mongotest')->selectCollection('test');
$collection->insert(array(
    'x' => 1
));

sleep(1);

$collection->insert(array(
    'x' => 2
));

Howto new a query with regex in php?

I new a query as follow, but the execute result is empty, what is it wrong?
$query = new MongoDB\Driver\Query( array( 'FieldName' => new MongoDB\BSON\Regex( '/^Test/', 'i' ) ), array( 'sort' => array( 'OrderBy' => -1 ) ) );

Failure to compile with pecl or phpize

Either running pecl install mongodb or:

git clone https://github.com/mongodb/mongo-php-driver.git mongo
cd mongo
git submodule init
git submodule update
phpize
./configure
make
sudo make install

(It never gets past phpize.)

Results in the following:

Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
config.m4:481: error: undefine: undefined macro: AC_TYPE_NAME
src/libbson/build/autotools/m4/ac_compile_check_sizeof.m4:25: AC_COMPILE_CHECK_SIZEOF is expanded from...
src/libbson/build/autotools/m4/ac_create_stdint_h.m4:503: AC_CREATE_STDINT_H is expanded from...
config.m4:481: the top level

autom4te-2.69: /usr/bin/m4 failed with exit status: 1

On OpenBSD 5.8, PHP 5.6. Any ideas?

Issue with pcntl_fork()

When using pcntl_fork() with the new MongoDB\Driver it is impossible to create a new MongoDB manager in the child process if one has been opened in the parent process.

Test script:

$manager1 = MongoDB\Driver\Manager('mongodb://localhost:27017');

$pid = pcntl_fork();

if ($pid == 0)
{
   // Child process, create a new manager here
   unset($manager1);
   $manager2 = MongoDB\Driver\Manager('mongodb://localhost:27017');

   // Perform queries with $manager2 here
}
else
{
   // Parent process, retain old manager
   // Perform queries with $manager1 here
}

Expected to have a new MongoDB connection in $manager2 that the child process can use. But both managers, even the newly created on in the child process seem to share a socket to MongoDB and throw errors based on receiving each others responses.

FTBFS on i386

The package fails to build on i386 (32-bit) systems, which will prevent it entering any linux distro.

/«PKGBUILDDIR»/mongodb-1.1.1/src/bson.c: In function 'php_phongo_bson_visit_int64':
/«PKGBUILDDIR»/mongodb-1.1.1/src/bson.c:508:38: error: macro "add_assoc_stringl" passed 5 arguments, but takes just 4
  ADD_ASSOC_INT64(retval, key, v_int64);
                                      ^
In file included from /«PKGBUILDDIR»/mongodb-1.1.1/src/bson.c:38:0:
./phongo_compat.h:112:3: error: 'add_assoc_stringl' undeclared (first use in this function)
   add_assoc_stringl(zval, key, tmp, tmp_len, 0); \
   ^
/«PKGBUILDDIR»/mongodb-1.1.1/src/bson.c:508:2: note: in expansion of macro 'ADD_ASSOC_INT64'
  ADD_ASSOC_INT64(retval, key, v_int64);
  ^
./phongo_compat.h:112:3: note: each undeclared identifier is reported only once for each function it appears in
   add_assoc_stringl(zval, key, tmp, tmp_len, 0); \
   ^
/«PKGBUILDDIR»/mongodb-1.1.1/src/bson.c:508:2: note: in expansion of macro 'ADD_ASSOC_INT64'
  ADD_ASSOC_INT64(retval, key, v_int64);
  ^
make[1]: *** [src/bson.lo] Error 1

Full build log available here: https://launchpadlibrarian.net/232231890/buildlog_ubuntu-wily-i386.php-mongodb_1.1.1-1%2Bdeb.sury.org~wily%2B2_BUILDING.txt.gz

php 7 support

When trying to install mongodb with pecl install mongodb I get
pecl/mongodb requires PHP (version >= 5.4.0, version <= 5.99.99), installed version is 7.0.0

phpize failed

/usr/bin/m4:config.m4:438: cannot open src/libmongoc/build/autotools/WeakSymbols.m4': No such file or directory /usr/bin/m4:config.m4:439: cannot opensrc/libmongoc/build/autotools/m4/ax_pthread.m4': No such file or directory
/usr/bin/m4:config.m4:473: cannot open src/libbson/build/autotools/CheckAtomics.m4': No such file or directory /usr/bin/m4:config.m4:474: cannot opensrc/libbson/build/autotools/FindDependencies.m4': No such file or directory
/usr/bin/m4:config.m4:475: cannot open src/libbson/build/autotools/m4/ac_compile_check_sizeof.m4': No such file or directory /usr/bin/m4:config.m4:476: cannot opensrc/libbson/build/autotools/m4/ac_create_stdint_h.m4': No such file or directory
/usr/bin/m4:config.m4:520: cannot open src/libmongoc/build/autotools/Versions.m4': No such file or directory /usr/bin/m4:config.m4:534: cannot opensrc/libbson/build/autotools/Versions.m4': No such file or directory

Random MongoDB\Driver\Exception\RuntimeException

I'm getting some seemingly random MongoDB\Driver\Exception\RuntimeException. For example:

PHP Fatal error:  Uncaught exception 'MongoDB\Driver\Exception\RuntimeException' in /vagrant/vendor/mongodb/mongodb/src/Operation/CreateIndexes.php:93
Stack trace:
#0 /vagrant/vendor/mongodb/mongodb/src/Operation/CreateIndexes.php(93): MongoDB\Driver\Server->executeCommand('test', Object(MongoDB\Driver\Command))
#1 /vagrant/vendor/mongodb/mongodb/src/Operation/CreateIndexes.php(72): MongoDB\Operation\CreateIndexes->executeCommand(Object(MongoDB\Driver\Server))
#2 /vagrant/vendor/mongodb/mongodb/src/Collection.php(194): MongoDB\Operation\CreateIndexes->execute(Object(MongoDB\Driver\Server))
#3 /vagrant/vendor/mongodb/mongodb/src/Collection.php(163): MongoDB\Collection->createIndexes(Array)

I've also gotten this exception when doing simple Find, BulkWrite, and others. It does not happen every time, seems random.

I'm not getting any message with the exception, so I don't really know what's wrong. Any tips?

Turn off automatic serialization

Is there any way to turn off the automatic serialization and have the driver behave like the older legacy driver as far as read and writing documents is concerned, IE just provide a serialization to and from array objects.

this is to avoid

  1. The insertion of type annotations into the on disk format
  2. The need to inherit data classes from the driver type hierarchy. (makes building storage adapters that target multiple storage systems near impossible).

I get that there is a need to be able provide support for extending functionality of the driver. But this attempt to convert the driver into an ORM is a step too far. I dont want class factories in my database driver, if i want them I will provide my own. Or I will use an ORM layer that suits my needs.

Can't make query with ISOdate values

I had ported my project from outdated "mongo" pecl extension to "mongodb". But I can't to make query with date. For example:

 $q = new MongoDB\Driver\Command([
            'mapreduce' => $collection,
            'map' => $map,
            'reduce' => $reduce,
            'finalize' => $finalize,
            'query' => $query,
            'sort' => $sort,
            'out' => ['inline' => 1]
        ]);
$response = $this->_connectionManager->executeCommand('mydb', $q);

where:

$query = new MongoDB\Driver\Query(['date' => new \MongoDB\BSON\UTCDatetime(1450137600 * 1000)]);

or

$query = new MongoDB\Driver\Query(['date' => [ '$lte' => new \MongoDB\BSON\UTCDatetime(1450137600 * 1000)]]);

I tried to use DateTime, simple ISODate value, but nothing working for me (for simple find commands also). Please, help me with example of date querying.

explain details for update query

Hi, i am try to capture data given by explain function for update based queries but its not working but Its working fine for find based queries. Is there any plain for the same ??

The DSP mongodb.dsp does not exist

I seem to be getting an error: "The DSP mongodb.dsp does not exist" when I try to install this via the "pecl install mongodb-beta" command.

Anyone have any ideas on why this might be happening, and what I can do to fix it?

I'm running Windows 7 x64. If it's not possible to install this on Windows via PECL, is there a different way to get use this library?

Let me know, thanks!

php7 install error

$ git clone -b PHP7 https://github.com/mongodb-labs/mongo-php-driver-prototype.git
$ cd mongo-php-driver-prototype
$ git submodule update --init
$ phpize
$ ./configure
$ make -j6 all

-op.c -fPIC -DPIC -o src/libmongoc/src/mongoc/.libs/mongoc-matcher-op.o
/opt/mongo-php-driver-prototype/src/libmongoc/src/mongoc/mongoc-matcher-op.c: In function '_mongoc_matcher_op_compare_new':
/opt/mongo-php-driver-prototype/src/libmongoc/src/mongoc/mongoc-matcher-op.c:166: error: #pragma GCC diagnostic not allowed inside functions
/opt/mongo-php-driver-prototype/src/libmongoc/src/mongoc/mongoc-matcher-op.c:167: error: #pragma GCC diagnostic not allowed inside functions
/opt/mongo-php-driver-prototype/src/libmongoc/src/mongoc/mongoc-matcher-op.c:172: error: #pragma GCC diagnostic not allowed inside functions
make: *** [src/libmongoc/src/mongoc/mongoc-matcher-op.lo] Error 1

Cannot append reference to bson

My environment:

  • Win 10
  • IIS 10
  • PHP 7.0.0 NTS x64 / PHP 5.5.20 TS x64 with FastCGI
  • mongodb 3.2.0
  • mongodb (php driver) 1.1.1

I failed to write associative array with reference value to db.

The following codes should reproduce this issue:

$some_field = array();

$data = array(
    'some_field' => &$some_field
);

$bulk = new BulkWrite();
$bulk->insert($data);

The exception message is:
PHP Fatal error: Uncaught MongoDB\Driver\Exception\UnexpectedValueException: Got unsupported type 10 'unknown'
Type 10 is IS_REFERENCE defined in zend_types.h

It works after removing the & operator in line 3.

Missing OpenSSL headers OSX 10.11

I am using http://php-osx.liip.ch and I am trying to install mongodb locally on my dev machine (OS X 10.11). Dont get confused by the php5 path, this one is symlinked to the proper php7 path. I had no problems installing it in my vagrant boxes though. Maybe you have a hint how to get it installed.

I already reinstalled the xcode cli tools.

git:(php7) ✗ php --version
PHP 7.0.1 (cli) (built: Dec 19 2015 11:03:48) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

git:(php7) ✗ sudo pecl install mongodb
Password:
downloading mongodb-1.1.1.tgz ...
Starting to download mongodb-1.1.1.tgz (642,977 bytes)
.................................................................................................................................done: 642,977 bytes
349 source files, building
running: phpize
Configuring for:
PHP Api Version:         20151012
Zend Module Api No:      20151012
Zend Extension Api No:   320151012
building in /private/tmp/pear/temp/pear-build-rootr7JiFb/mongodb-1.1.1
running: /private/tmp/pear/temp/mongodb/configure --with-php-config=/usr/local/php5/bin/php-config
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-apple-darwin15.2.0
checking host system type... x86_64-apple-darwin15.2.0
checking target system type... x86_64-apple-darwin15.2.0
checking for PHP prefix... /usr/local/php5
checking for PHP includes... -I/usr/local/php5/include/php -I/usr/local/php5/include/php/main -I/usr/local/php5/include/php/TSRM -I/usr/local/php5/include/php/Zend -I/usr/local/php5/include/php/ext -I/usr/local/php5/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php5/lib/php/extensions/no-debug-non-zts-20151012
checking for PHP installed headers prefix... /usr/local/php5/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk is broken... no
checking whether to enable mongodb support... yes, shared
checking OpenSSL dir for mongodb... yes
checking PHP version... 70001
checking whether to enable developer build flags... no
checking whether to enable code coverage... no
checking Use system libbson... no
checking configuring libmongoc... ...
checking Use system libmongoc... no
checking for pkg-config... no
configure: error: Cannot find OpenSSL's <evp.h>
ERROR: `/private/tmp/pear/temp/mongodb/configure --with-php-config=/usr/local/php5/bin/php-config' failed

Issue with Collection->findOne()

When I try and use the MongoDB\Collection->findOne, my PHP script completely dies without even returning any kind of error. If I open my apache logs I see:

/var/tmp/mongodb/src/libmongoc/src/mongoc/mongoc-cursor.c:52 _mongoc_n_return(): precondition failed: remaining > 0
[Tue Dec 22 21:35:46.198539 2015] [core:notice] [pid 812] AH00052: child pid 2206 exit signal Aborted (6)

I'm running on CentOS 7 and I know the query should be returning a single result.

$mongo = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$receipts = new MongoDB\Collection($mongo, $databaseName.".receipts");

$r = $receipts->findOne(["receipt_id" => 1062792739]);

Change findOne() to find() and I have no issue. Cursor is returned with a single result.

The extension works locally but fails on travis.

This is what I get on travis:

1.58s$ phpunit
PHPUnit 4.8.21 by Sebastian Bergmann and contributors.
......./tmp/pear/temp/mongodb/src/libmongoc/src/mongoc/mongoc-cursor.c:52 _mongoc_n_return(): precondition failed: remaining > 0
/home/travis/build.sh: line 45: 25859 Aborted                 (core dumped) phpunit

But locally it works just fine, here's what I have locally:

vagrant@precise64:~/projects/Payum/PayumServer$ php -v
PHP 5.5.30-1+deb.sury.org~precise+1 (cli) (built: Oct  4 2015 16:14:34) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
    with Xdebug v2.3.2, Copyright (c) 2002-2015, by Derick Rethans

extension:

vagrant@precise64:~/projects/Payum/PayumServer$ php -i | grep mongodb
/etc/php5/cli/conf.d/20-mongodb.ini,
mongodb
mongodb support => enabled
mongodb version => 1.0.1
mongodb stability => stable
mongodb.debug => no value => no value

Windows support

This repo does not have the config to compile the extension on Windows.

Making the extension compatible with Windows seems a must-have to me (even though I'm not using Windows myself anymore)

bson and mongoc versions in Windows builds

When building on windows with http://pecl.php.net/get/mongodb-1.1.1.tgz the versions are reported as follows:

mongodb version     1.1.1 
mongodb stability   stable 
libmongoc version   1.1.2 
libbson version     1.1.3

However, looking at VERSION_CURRENT and VERSION_RELEASED in src/libbson and src/libmongoc in that tarball libbson seems v1.3.0 and libmongoc is v1.3.1-dev. Can the win32/*-version.h files be updated? In an ideal world that would be done automatically by the pecl packaging script, but I do not know if that is possible.

Creating indexes

Hello

I couldn't find any example using the new MongoDB Driver (using it in PHP7 fwiw) on how to run commands such as createIndex/ensureIndex on a collection?

I tried using the executeCommand method, but it seems like it's intended only for management/administration commands, and not collection methods.

Thanks!

None of the MongoDB\Driver\BSON types implement the JsonSerializable interface

It may sound odd that this is an issue, but because these types all use private members with public accessors they end up printing nothing when you json_encode them.

Consider the following example data:

$testTable = ["_id" => new MongoDB\BSON\ObjectID(), "date" => new MongoDB\BSON\UTCDateTime(time())];

attempting to print it like

print(json_encode($testTable));

will give the following result:

{"_id":{},"date":{}}

I can work around this for now by using a pretty silly pattern

print(MongoDB\BSON\toJSON(MongoDB\BSON\fromPHP($testTable)));

which gives the expected

{ "_id" : { "$oid" : "569d0d892bdc4839a80017da" }, "date" : { "$date" : 1453133887 } }

but would rather not convert data repeatedly (consider that it's already in BSON in mongo itself, gets converted to PHP and then when I'm done manipulating, I convert back to BSON just to be able to convert to JSON...)

Public variables will fix this issue too, if implementing JsonSerializable is undesired.

edit: Because MongoDB\BSON\toJSON does not have any options, the workaround does not handle any case where the user needs to make use of the json_encode options like JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT, JSON_PRESERVE_ZERO_FRACTION, JSON_UNESCAPED_UNICODE, JSON_PARTIAL_OUTPUT_ON_ERROR

Segmentation fault when specifying username and password

Hi there.

I've noticed that when you specify a username and password in the URI and access control isn't being used, a segmentation fault occurs. Try the following script on a Laravel Homestead VM.

<?php

$manager = new MongoDB\Driver\Manager('mongodb://foo:[email protected]/test');
$server = $manager->selectServer(new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY));
$server->executeQuery('db.collection', new MongoDB\Driver\Query([]));
# ~/.homestead/after.sh
# MongoDB
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

sudo apt-get update
sudo apt-get install mongodb-org pkg-config libsasl2-dev -y

sudo pecl install mongodb

echo 'extension=mongodb.so' | sudo tee /etc/php5/mods-available/mongodb.ini
sudo ln -s /etc/php5/mods-available/mongodb.ini /etc/php5/fpm/conf.d/mongodb.ini
sudo ln -s /etc/php5/mods-available/mongodb.ini /etc/php5/cli/conf.d/mongodb.ini

sudo service php5-fpm restart

Not critical but it threw one of the unit tests I was using.

Cant count result

ON previous mongo driver you had all the result functions ->count()
It seems the new driver lacks the counting function

$coleccion->find()->count() is missing, it is impossible to count result on phongo

License?

Folks, the package.xml (and PECL) says "New BSD License", but the LICENSE file is Apache 2.0. Could you please fix the discrepancy?

PHP Driver not playing well with Curl

This is a very weird issue. For some reason, very randomly, if you do a Curl request to a new website after initialising the Mongo driver, the eventual "upsert" fails with no proper debug message.

The weird part is, it does not happen with all domains, such as http://yahoo.com/ works. Probably its different for different HTTP response types?

I checked for potential variable name conflicts, but I see none. Can anyone else duplicate this?

Mongo server, mongo client libraries - all latest versions; PHP 5.6

Code below:

$manager = new MongoDB\Driver\Manager("mongodb://192.168.99.100/");
$collection = new MongoDB\Collection($manager, "test_database." . 'test_collection');

$indexes = [
    ['key' => ['name' => 1, 'age' => 1], 'unique' => true, 'sparse' => true],
    ['key' => ['timestamp' => 1]]
];
$collection->createIndexes($indexes);
$doc = array('name' => 'john', 'age'=> 20);

// a random curl request
$objCurl = curl_init();
curl_setopt($objCurl, CURLOPT_VERBOSE,1);

// very random behaviour, some website triggers the mongo error below, some do not!!!?!?!!!
curl_setopt($objCurl, CURLOPT_URL, 'http://www.whatever.com');
$result = curl_exec($objCurl);

// mongo upsert
$cond = array('name' => 'john', 'age' => 20);
$ret = $collection->updateOne($cond,
    array('$set' => $doc, '$currentDate' => array('timestamp' => true)),
    array('upsert' => true));

Output below:

php test.php
* Rebuilt URL to: http://www.whatever.com/
* Hostname was NOT found in DNS cache
*   Trying 198.57.151.250...
* Connected to www.whatever.com (198.57.151.250) port 80 (#0)
> GET / HTTP/1.1
Host: www.whatever.com
Accept: */*

< HTTP/1.1 301 Moved Permanently
* Server nginx/1.8.0 is not blacklisted
< Server: nginx/1.8.0
< Date: Sat, 12 Dec 2015 06:14:11 GMT
< Content-Type: text/html; charset=UTF-8
< Content-Length: 0
< Connection: keep-alive
< Location: http://whatever.com/
<
* Connection #0 to host www.whatever.com left intact
[12-Dec-2015 06:14:12] ERR (3):
#0 /home/grepsr/vortex-backend/library/MongoDB/Operation/Update.php(107): MongoDB\Driver\Server->executeBulkWrite('test_database.t...', Object(MongoDB\Driver\BulkWrite), Object(MongoDB\Driver\WriteConcern))
#1 /home/grepsr/vortex-backend/library/MongoDB/Operation/UpdateOne.php(66): MongoDB\Operation\Update->execute(Object(MongoDB\Driver\Server))
#2 /home/grepsr/vortex-backend/library/MongoDB/Collection.php(564): MongoDB\Operation\UpdateOne->execute(Object(MongoDB\Driver\Server))
#3 /home/grepsr/vortex-backend/test.php(36): MongoDB\Collection->updateOne(Array, Array, Array)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.