1

現在、オブジェクトのコレクションを反復処理して、1 つずつ保存しています。コレクション全体を直接保存する方法があると思いますか?

後で個々のオブジェクトを取得できる必要があることに注意してください (コレクション全体ではありません)。

4

1 に答える 1

2

DataStore クラスの javadoc から。古いバージョンでは使用できない場合があります。これでも、内部的に反復して一度に 1 つずつ保存していると思いますが、最適化される可能性があるため、自分で反復するよりもこれを使用することをお勧めします。

<T> Iterable<Key<T>>
save(Iterable<T> entities) 
          Saves the entities (Objects) and updates the @Id field
<T> Iterable<Key<T>>
save(Iterable<T> entities, com.mongodb.WriteConcern wc) 
          Saves the entities (Objects) and updates the @Id field, with the WriteConcern
<T> Iterable<Key<T>>
save(T... entities) 
          Saves the entities (Objects) and updates the @Id field

http://morphia.googlecode.com/svn/site/morphia/apidocs/com/google/code/morphia/Datastore.html#save(java.lang.Iterable )

于 2012-09-12T11:14:04.123 に答える