[英]MongoDB & PHP - Regex find query in nested array
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? 我如何使用0-8数组在下面的查询中查找()“级别”数据?
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 ) ) ) ) ) )
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. 但是,我不太明白为什么您在那里有一个“ 0”键。 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 ) ) ) );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.