-1

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 ) ) ) ) ) )
4

1 回答 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 ) ) ) );
于 2012-05-28T19:58:05.547 回答