2

i started with mongodb and played around with random temperature data like this:

'weather' => array(
                    'Air' => array(
                        'Jan' => 11,
                        'Feb' => 20,
                        'Mar' => 24,
                        'Jun' => 28,
                        'Jul' => 30
                    )
                ),

Now my question: How can i query the Air array ?

I knwo i can do somethin like:

$query = array('weather.Air.Jan' => 11);

Works fine...

But how can i search in the whole Air array:

$query = array('weather.Air.$' => 40);

This query doesn't work... Can somebody help me

1 Answer 1

2

Unfortunately, the query you're looking for does not exist.

As written, you're asking for "weather.Air where a key in the JSON object contains a value of 40".

MongoDB has the ability to "drill into" arrays. However, when it comes to sub-objects, you have to reach into the keys directly. There is no operator that provides a "search all keys" method. There is an outstanding JIRA request for this item right here.

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.