2013-10-28 2 views
0

mongodb (2.4.7 64 비트 Linux OS)를 사용하여 기존 mysql 데이터베이스를 대체 할 수 있는지 알아보기로했습니다. 꽤 깔끔한 upsert functionallity입니다 -하지만 여기에 문제가 있습니다. 누군가가 왜 "identification.YAHOO"=> "DTE.DE"키가 배열에 추가되지 않지만 "DETGY"에 의해 relaced되는지 설명 할 수 있습니까?임베디드 어레이의 upsert 값이 누락되었습니다

<?php 

    $oMongoClient = new MongoClient(); 
    $oMongoDB = $oMongoClient->test; 
    $oMongo = $oMongoDB->item; 

    $oMongo->update(
    array('$or' => array(
        array("identification.WKN" => "555750"), 
        array("identification.ISIN" => "DE005557504"), 
        array("identification.YAHOO" => "DTE.DE"), 
        array("identification.YAHOO" => "DTEGY"), 
        array("_id" => "lalala") 
       ) 
), 
    array(
    '$set' => array(
     "shortname" => "DT_TELEKOM", 
     "name" => array(
     "de" => "Deutsche Telekom AG", 
     "en" => "Deutsche Telekom AG Inc." 
    ), 
     "type" => "STOCK", 
     "web" => "http://deutschetelemom.com", 
     "valid_from" => "1998-01-01", 
     "valid_to" => "9999-12-31", 
     "inactive" => false, 
     "translate_all" => false, 
     "is_provisory" => false, 
     "touched" => "25.02.2013 17:11:54" 
    ), 
    '$addToSet' => array(
     "identification.WKN" => "555750", 
     "identification.ISIN" => "DE005557504", 
     "identification.YAHOO" => "DTE.DE", 
     "identification.YAHOO" => "DTEGY" 
    ) 
), 
    array("upsert" => true) 
); 

//$oMongo->ensureIndex(array('$**' => "text")); 
$oMongo->ensureIndex(array('$**' => "text")); 

$result = $oMongoDB->command(
    array(
     'text' => 'item', //this is the name of the collection where we are searching 
     'search' => 'DTEGY' 
    ) 
); 

print_r($result); 

인쇄

[results] => Array 
     (
      [0] => Array 
       (
        [score] => 1 
        [obj] => Array 
         (
          [_id] => MongoId Object 
           (
            [$id] => 526e647b7ebd4252592cfe52 
           ) 

          [identification] => Array 
           (
            [ISIN] => Array 
             (
              [0] => DE005557504 
             ) 

            [WKN] => Array 
             (
              [0] => 555750 
             ) 

            [YAHOO] => Array 
             (
              [0] => DTEGY 
             ) 

           ) 

          [inactive] => 
          [is_provisory] => 
          [name] => Array 
           (
            [de] => Deutsche Telekom AG 
            [en] => Deutsche Telekom AG Inc. 
           ) 

          [shortname] => DT_TELEKOM 
          [touched] => 25.02.2013 17:11:54 
          [translate_all] => 
          [type] => STOCK 
          [valid_from] => 1998-01-01 
          [valid_to] => 9999-12-31 
          [web] => http://deutschetelemom.com 
         ) 

       ) 

     ) 

당신은 키 DTE.DE가 누락 볼 수 있듯이.

답변

0

PHP의 연관 배열은 키당 하나의 항목 만 가질 수 있습니다. 이 같은 PHP 배열을 만들 때 그래서 :

array(
     "identification.WKN" => "555750", 
     "identification.ISIN" => "DE005557504", 
     "identification.YAHOO" => "DTE.DE", 
     "identification.YAHOO" => "DTEGY" 
) 

당신이 키 "identification.YAHOO"을 사용하는 두 번째 시간은 배열의 첫 번째 값을 대체합니다.

다행히 MongoDB의 $addToSet 연산자는 $each -operator와 결합 할 수 있습니다.이 연산자를 사용하면 하나의 키가 아닌 모든 키 값 배열을 전달할 수 있습니다. 내 PHP는 약간 녹슬지 만 작동해야합니다 :

array(
     "identification.WKN" => "555750", 
     "identification.ISIN" => "DE005557504", 
     "identification.YAHOO" => array(
      "$each" => array("DTE.DE", "DTEGY") 
    ) 
) 
+0

저에게 제 아내는 별개의 배열 키를 압수합니다 ... 이것은 꽤 잘 작동합니다! '$ 각 배열'=> 배열 ( "identification.WKN"=> "555750", "identification.ISIN"=> "DE005557504", "identification.YAHOO"=> 배열 ('$ each'=> 배열 "DTE.DE", "DTEGY")) ) – KIC