0

I have data like so:

{
   "_id": ObjectId("4fc3abc9751c38c811000002"),
   "timeStamp": ISODate("2012-05-28T16: 45: 58.0Z"),
   "loadTime": 2.3101460933685,
   "description": {
     "0": {
       "level": NumberInt(0),
       "description": "Some description"
    }
  },

How do I find() the "level" data using the array of 0-8 like in my query below?

My query looks like this:

find(Array ( [description] => Array ( [0] => Array ( [level] => Array ( [$in] => Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 ) ) ) ) ) )

1 Answer 1

3

This should do the trick:

->find( array( 'description.0.level' => array( '$in' => range( 0, 8 ) ) ) );

However, I don't quite see why you have a "0" key there. The document really should look like:

{
  "_id": ObjectId("4fc3abc9751c38c811000002"),
  "timeStamp": ISODate("2012-05-28T16: 45: 58.0Z"),
  "loadTime": 2.3101460933685,
  "description": [
    {
      "level": 0,
      "description": "Some description"
    }
  ],
}

In which case you can find the "level" like:

->find( array( 'description.level' => array( '$in' => range( 0, 8 ) ) ) );
1
  • It's a little confusing but there could be a record like: "description": { "0": { "level": NumberInt(0), "description": "Some description" }, "1": { "level": NumberInt(0), "description": "Some description" } Which is the reason for the "0" ... Commented May 28, 2012 at 22:49

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.