gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 04:40:44 27 4
gpt4 key购买 nike

我当前正在迭代对象集合并逐个保存它们。我想有办法直接保存整个集合吗?

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

最佳答案

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

关于java - 如何使用 Morphia 将对象集合保存到 MongoDB?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12383257/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com