0

I developed this piece of PHP code:

 $cursor = $collection->find
    (
        {
            username:
            {
                $in: ['admin', 'test']
            }
        }
    );

but this message was displayed:

Parse error: syntax error, unexpected '{'

I am using:

targetMinOS: Windows 10 (64 bits)

db version v3.6.4

According to the MONGODB documentation, this code is right.

What's wrong?

UPDATE: This question was marked as duplicate but the referenced link doesn't mention this question which is specific of my code.

UPDATE #2 : This question was solved thanks to Neil Lunn and Deceze comments. I was wrong why I took a look to the MongoDB Shell documentation. My fault.

Community
  • 1
  • 1
  • 3
    It's PHP and not JavaScript. Use `[]` or `array()` instead of `{}`. You also need to quote `''` your keys with PHP, and of course `=>` and not `:`. Different language to the documentation. – Neil Lunn May 11 '18 at 09:05
  • Example: https://stackoverflow.com/questions/5334723/how-to-query-mongo-in-php – Messa May 11 '18 at 09:07
  • Since I am following the notation provided by MongoDB, I consider this syntax is right. Please, click on link to verify it. – Abelardo León González May 11 '18 at 09:12
  • 1
    That *server* Mongo manual gives all samples in Javascript which work on the mongo console. What you want is to look specifically at your PHP driver documentation: https://docs.mongodb.com/php-library/current/tutorial/crud/ – deceze May 11 '18 at 09:41
  • The presumed error is located at the first '{' (line # 3 of this piece of code) – Abelardo León González May 11 '18 at 09:42

0 Answers0