1

Data stored in collection as below

 [field_1] => Array
                (
                    [fields] => Array
                        (
                            [0] => MongoInt64 Object
                                (
                                    [value] => 1233
                                )

                            [1] => MongoInt64 Object
                                (
                                    [value] => 1234
                                )

                        )

                )

I need to search 1234 in field.

I used below code in php to search

$param = array('field_1.fields.$' => 1234);

But this is not working

1 Answer 1

3

You need to use the $in query criteria, to find elements within an array

$cursor = $collection->find(array("field_1.fields" => array('$in' => array("1234"))));

This will find all items that have 1234 within "fields"

$in doc: https://docs.mongodb.org/v3.0/reference/operator/query/in/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.