dongluxin6711 2013-01-16 10:11
浏览 27
已采纳

MongoDB找到$ in

I am trying to look on the field:

[case-file-header] => Array (
                      [filing-date] => 20130111)

like this:

$cursor = $mongo->$db->$collection->find(array('case-file-header'=>
                                                     array('filing-date' => 
                                                                 array('$in' => array($current_date)))));

what am I doing wrong?

My collection consists of 7 million records. Here's an example of one record:

[_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
 )
  • 写回答

1条回答 默认 最新

  • dsbiw2911188 2013-01-16 10:17
    关注

    You should really use the positional operator instead since MongoDB will actually try something else when you make nesting like:

    array('case-file-header'=>
    array('filing-date' => 
    

    So:

    $mongo->$db->$collection->find(array(
        'case-file-header.filing-date' => array('$in' => array($current_date))
    ));
    

    Should work

    This is an exact sample that works with the doc you showed:

    $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();
    

    With the output being:

    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)
    

    So there must be something else wrong somewhere

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形