mongodb / laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
https://www.mongodb.com/docs/drivers/php/laravel-mongodb/
MIT License
7.01k stars 1.43k forks source link

bson_append_array(): invalid array detected warning? #2300

Closed AlexLightning closed 2 years ago

AlexLightning commented 3 years ago

Description:

I have this model:

<?php

namespace App;

use Illuminate\Database\Eloquent\SoftDeletes;
use Jenssegers\Mongodb\Eloquent\Model;

class RawData extends Model
{
    protected $collection = 'files';

    protected $connection = 'mongodb';
}

And in a job I use it like this:

$raw_data = RawData::where(['project_id'    => $project->id, 'user_id' => $user->id])->simplePaginate($this->take);

echo count($raw_data), PHP_EOL;

The job executes well and does what it is supposed to do, but in the logs I keep seeing this: bson_append_array(): invalid array detected. first element of array parameter is not "0".

Any idea why and if it seems to be something wrong on my side or a bug?

Thanks!

denis-chmel commented 3 years ago

Stumbled upon this recently, do you have a solution? Let's align if not. I've noticed it's not even related to any find request, simply connecting to mongo (calling Manager::selectServer) causes several of such. Also I have this on remote machine, but not on local one, on the same branch (same codebase), so hardly it's because of a laravel or its plugins. PHP is 7.4.22, Laravel version I think is irrelevant.

What's different - local one uses local mongodb, remote (where I get that warning) uses AWS DocumentDB. Is this your case too? AWS DocumentDB?

Database Driver & Version: MongoDB 4.0.0 Community

How do you check this? if by db.version() then I have 4.0.0 on the AWS DocmentDB, and 5.0.0 loally (MongoDB), maybe that's it? Something is not compatible with AWS Docment DB. I am just not sure what exactly, I digged into sources and found that the warning is generated even with native MongoDB\Driver\Manager::selectServer, which means the issue is either inside a monodb module, or with some parameters that is passed to it. But I could not find any parameters that look like an array (and the warning is about array with no "0" key).

Apart from that, the only difference in php -i | grep mongo for me is: remote (where I have warnings)

libmongoc ICU => disabled

locally (no warnings)

libmongoc ICU => enabled

But I am not sure what is this, how to toggle it. Maybe it's irrelevant. Here is the full result where I have those warnings

$ php -i | grep mongo
mongodb
libmongoc bundled version => 1.18.0
libmongoc SSL => enabled
libmongoc SSL library => OpenSSL
libmongoc crypto => enabled
libmongoc crypto library => libcrypto
libmongoc crypto system profile => disabled
libmongoc SASL => disabled
libmongoc ICU => disabled
libmongoc compression => enabled
libmongoc compression snappy => disabled
libmongoc compression zlib => enabled
libmongoc compression zstd => disabled
libmongocrypt bundled version => 1.2.1
libmongocrypt crypto => enabled
libmongocrypt crypto library => libcrypto
mongodb.debug => no value => no value
AlexLightning commented 3 years ago

I encountered some problems using this so I eventually let mongo on hold. But I can give you some information:

Indeed on local it worked fine, with a normal mongodb instance and these logs appear on a production server that uses amazon documentdb. The only thing I could think of is that this is the problem. DocumentDB is not officialy supported by this package and I know that it is not exactly like normal mongodb. We were aware of this, but because it was easier to setup we went that way anyway.

I saw the mongodb version while using mongodb compass to connect to it. I was in the same situation as you 5 on local, 4 on server.

denis-chmel commented 3 years ago

Thanks for confirming, buddy. I guess to suppress those warnings we just need to switch to MongoDB official, not use AWS DocumentDB. However, that warning is the only issue I have found so far. But It's very annoying though.

fraroas commented 3 years ago

I'm having this warning, too. On DocumentDB. If you go a bit deeper into the mongo-c-driver, you find the root if this warning in parsing the "saslSupportedMechs" array. You won't find a SAML configuration on your simple local installation, but for AWS it probably makes sense to use something like LDAP for auth. The warning is indeed correct, the array key is not "0" but (debug with bson_as_json) { "saslSupportedMechs" : "SCRAM-SHA-1" }. It's only a warning as there seems to be no malfunction. But it creates a lot of noise in your log.

I expect a shitstorm when I file this as bug at MongoDB, so any hints for surpressing the error are highly appreciated (beside remove the warning in the driver) .

mihitha commented 3 years ago

I recently migrated some servers from Mongo to DocumentDB and I am having the same issue. It seems mongo PHP driver is not 100% compatible with DocumentDB or could be a bug in the AWS documentDB engine.

I am not sure where to file a bug report for DocumentDB ?

denis-chmel commented 2 years ago

Someone posted on SO two months ago, but no answers there yet. https://stackoverflow.com/questions/69670396/mongodb-documentdb-bson-append-array-invalid-array-detected-first-element-of

divine commented 2 years ago

Hello,

This issue has nothing to do with this library as it's related to driver compatibility problems with DocumentDB.

Contact AWS ask why its API isn't compatible with what they've promised.

See: https://www.mongodb.com/atlas-vs-amazon-documentdb

Related #2077, #1709

Thanks!

JLepeltier commented 2 years ago

I'm having this warning, too. On DocumentDB. If you go a bit deeper into the mongo-c-driver, you find the root if this warning in parsing the "saslSupportedMechs" array. You won't find a SAML configuration on your simple local installation, but for AWS it probably makes sense to use something like LDAP for auth. The warning is indeed correct, the array key is not "0" but (debug with bson_as_json) { "saslSupportedMechs" : "SCRAM-SHA-1" }. It's only a warning as there seems to be no malfunction. But it creates a lot of noise in your log.

If you add "&authMechanism=SCRAM-SHA-1" to the connexion string, the warning disepear.