简体   繁体   English

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

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

I am currently iterating over a collection of objects and saving them one by one.我目前正在迭代一组对象并一个一个地保存它们。 I suppose there is a way to save the entire collection directly?我想有一种方法可以直接保存整个集合吗?

Note, I would need to be able to retrieve each individual objects later (not the whole collection).请注意,我稍后需要能够检索每个单独的对象(而不是整个集合)。

From the javadoc of the DataStore class.来自 DataStore 类的 javadoc。 The might not be available on older versions.旧版本可能不可用。 Even this I think is internally iterating and saving one at a time - but it might get optimized, so it is better to use this than iterate yourself.即使这我认为是在内部迭代并一次保存一个 - 但它可能会得到优化,所以最好使用它而不是自己迭代。

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