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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。