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 万件のレコードで構成されています。1 つのレコードの例を次に示します。

[_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 に答える