繁体   English   中英

如何使用 Morphia 将对象集合保存到 MongoDB?

[英]how to save a collection of objects to MongoDB with Morphia?

我目前正在迭代一组对象并一个一个地保存它们。 我想有一种方法可以直接保存整个集合吗?

请注意,我稍后需要能够检索每个单独的对象(而不是整个集合)。

来自 DataStore 类的 javadoc。 旧版本可能不可用。 即使这我认为是在内部迭代并一次保存一个 - 但它可能会得到优化,所以最好使用它而不是自己迭代。

<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 )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM