0

我想看看现场:

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

1 回答 1

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)

所以一定有别的地方不对劲

于 2013-01-16T10:17:58.900 回答