2012-03-31 13 views
2

PHPとMongoDBの新機能ですので、皆さんからいくつかの提案があれば本当に役に立ちます。私はこのループを何時間も悩ませてきましたが、役に立たないものです。MongoDBのinsertステートメントの記述

while ($currentCol<$maxCols){ 
    $obj = array($currentarray[0][$currentCol] => $currentarray[$currentRow][$currentCol]); 
    $collection->insert($obj); 
    echo $testing; 
    echo "<br />"; 
    print_r ($obj); 
    echo "<br />"; 
    $testing++; 
    $currentCol++; 
} 

それは出力:

これは大体私の入力である

1 
Array ([President ] => George Washington [_id] => MongoId Object ([$id] => 4f774d924f62e5ca37000160)) 
2 
Array ([Wikipedia Entry] => http://en.wikipedia.org/wiki/George_Washington [_id] => MongoId Object ([$id] => 4f774d934f62e5ca37000161)) 
3 
Array ([Took office ] => 30/04/1789 [_id] => MongoId Object ([$id] => 4f774d934f62e5ca37000162)) 
4 
Array ([Left office ] => 4/03/1797 [_id] => MongoId Object ([$id] => 4f774d934f62e5ca37000163)) 
5 
Array ([Party ] => Independent [_id] => MongoId Object ([$id] => 4f774d934f62e5ca37000164)) 
6 
Array ([Portrait] => GeorgeWashington.jpg [_id] => MongoId Object ([$id] => 4f774d934f62e5ca37000165)) 
7 
Array ([Thumbnail] => thmb_GeorgeWashington.jpg [_id] => MongoId Object ([$id] => 4f774d934f62e5ca37000166)) 
8 
Array ([Home State] => Virginia [_id] => MongoId Object ([$id] => 4f774d934f62e5ca37000167)) 

私がいる最後の問題は、実際には、複数のINSERT文を持つのではなく、1つのINSERT文にすべてを組み合わせることですあなたは上記を参照してください。したがって、8つのinsert文を生成する代わりに、1つのinsert文を作成するようにしています。

提案がありますか?

答えて

1

MongoDBにはトランザクションがありません。挿入は高速で軽量です。そのような少数のために挿入してみる特別な理由はありません。これまで私が使ったことはありませんが、試してみるとBatchInsert methodです。

+0

ええ、私のコードは入力されたCSVファイルを取るので、大量のレコードも処理できなければなりません。 – EGHDK

+0

BatchInsertメソッドを使ってみましたが、必要なものに変更していないようです。他のアイデア? – EGHDK

+0

私が理解しているあなたの質問に基づいて、BatchInsertルーチンを使うべきです。私はあなたがどんな問題を抱えているかについてはっきりしていません。 – gview

関連する問題