PHP Fatal error: Uncaught Error: Call to undefined function MongoDB\is_document() in ../vendor/mongodb/mongodb/src/Operation/Find.php:166

I suddenly get this error:
Fatal error: Uncaught Error: Call to undefined function MongoDB\is_document() in /vendor/mongodb/mongodb/src/Operation/Find.php:166

thrown in /Users/kka02/Documents/GitHub/zwemindex/data/_php/vendor/mongodb/mongodb/src/Operation/Find.php on line 166

This happens when calling the find/findOne fuction.

It used to work. I changed to 1.16 but after reverting to 1.15 it still is broken.
I have no clue what could cause the error.

I tested my query again in compass, and that works as well.

MongoDB\is_document was introduced in version 1.16 of the library. The error you posted for 1.16 indicates that the functions.php file was not correctly autoloaded. Do you use composer to install the library, and if so, can you please confirm that the file is correctly included? You can do so by following the autoloader initialisation trail from vendor/autoload.php. In my case, the autoloader class in vendor/autoload_static.php contains a $files property that correctly includes the src/functions.php file.

The other error after downgrading to 1.15 however makes me think there are some additional issues going on. After downgrading, the find operation should no longer use is_document, so something fishy is going on. If the error appears only in a web SAPI (e.g. php-fpm), make sure to restart the FPM process to ensure no autoloaded code remains. One way to confirm this would be to try this in the CLI - the error should not appear there as it always starts from a clean slate without code loaded and typically without an I-cache.

@Andreas_Braun Thanks. I noticed that I downgraded in the wrong directory. I can confirm that downgrading to 1.15 solved the issue.

After that I upgraded to 1.16 again, and I didn’t got the error. So probably something went wrong with my first upgrade.

Thanks for your confirmation it was related to 1.15/1.16.