我试着看看这个领域:
[case-file-header] => Array (
[filing-date] => 20130111)
像这样:
$cursor = $mongo->$db->$collection->find(array('case-file-header'=>
array('filing-date' =>
array('$in' => array($current_date)))));
我做错了什么?
我的收藏包含700万条记录。以下是一条记录的示例:
[_id] => MongoId Object (
[$id] => 50f5a5630c7263b79a373390
)
[serial-number] => 76713205
[registration-number] => 0000000
[transaction-date] => 20130114
[case-file-header] => Array (
[filing-date] => 20130111
[status-code] => 630
[status-date] => 20130114
[mark-identification] => ALPHACHEMICAL
[mark-drawing-code] => 3000
[attorney-docket-number] => 113,328
[attorney-name] => William Nitkin
[principal-register-amended-in] => F
[supplemental-register-amended-in] => F
[trademark-in] => T
[collective-trademark-in] => F
[service-mark-in] => F
[collective-service-mark-in] => F
[collective-membership-mark-in] => F
[certification-mark-in] => F
)
答案 0 :(得分:2)
你应该使用位置运算符,因为当你进行嵌套时,MongoDB会尝试其他的东西:
array('case-file-header'=>
array('filing-date' =>
所以:
$mongo->$db->$collection->find(array(
'case-file-header.filing-date' => array('$in' => array($current_date))
));
应该工作
这是一个与您展示的文档一起使用的确切示例:
$mongo = new Mongo();
$db = $mongo->mydb;
$current_date = 20130111;
$db->some_test_collection->insert(array(
'_id' => new MongoId('50f5a5630c7263b79a373390'),
'serial-number' => 76713205,
'registration-number' => 0000000,
'transaction-date' => 20130114,
'case-file-header' => Array(
'filing-date' => 20130111,
'status-code' => 630,
'status-date' => 20130114,
'mark-identification' => 'ALPHACHEMICAL',
'mark-drawing-code' => 3000,
'attorney-docket-number' => '113,328',
'attorney-name' => 'William Nitkin',
'principal-register-amended-in' => 'F',
'supplemental-register-amended-in' => 'F',
'trademark-in' => 'T',
'collective-trademark-in' => 'F',
'service-mark-in' => 'F',
'collective-service-mark-in' => 'F',
'collective-membership-mark-in' => 'F',
'certification-mark-in' => 'F'
)
));
$cursor = $db->some_test_collection->find(array('case-file-header.filing-date' => array('$in' => array($current_date))));
foreach($cursor as $row) var_dump($row);
var_dump($cursor->count());
exit();
输出为:
int 1
array
'_id' =>
object(MongoId)[5]
public '$id' => string '50f5a5630c7263b79a373390' (length=24)
'serial-number' => int 76713205
'registration-number' => int 0
'transaction-date' => int 20130114
'case-file-header' =>
array
'filing-date' => int 20130111
'status-code' => int 630
'status-date' => int 20130114
'mark-identification' => string 'ALPHACHEMICAL' (length=13)
'mark-drawing-code' => int 3000
'attorney-docket-number' => string '113,328' (length=7)
'attorney-name' => string 'William Nitkin' (length=14)
'principal-register-amended-in' => string 'F' (length=1)
'supplemental-register-amended-in' => string 'F' (length=1)
'trademark-in' => string 'T' (length=1)
'collective-trademark-in' => string 'F' (length=1)
'service-mark-in' => string 'F' (length=1)
'collective-service-mark-in' => string 'F' (length=1)
'collective-membership-mark-in' => string 'F' (length=1)
'certification-mark-in' => string 'F' (length=1)
所以某处肯定会出现其他问题