Spring 数据 Mongo 链接文档存储
Spring Data Mongo Linked Document Storage
是否有 Spring 数据 Mongo 的模式支持将 link 保存到单独集合中的单独文档,并在其退出时自动重新水合数据库?
@Document
class Person <-- Saves to the Person Collection
@id
UUID id
String name
Address address
@Document
class Address --
@id
UUID id
String address1
...
调用 save(person)
我希望数据库中的地址 属性 反映地址 ID,并将地址对象持久保存到地址集合中。当我把 Person 拉回来时,Address 会完全水合(或者可能是懒惰?)并且可以访问。
- Spring数据Mongo3.1
- Spring 启动 2.4
- Groovy 2.5
- JDK11
在撰写本文时 Spring 数据 MongoDB 3.2 仅支持 link 通过 DBRefs 编辑文档。然而,它们遵循固定结构,因此在目标文档中表示 link 的值看起来像这样
{ "$ref" : <value>, "$id" : <value>, "$db" : <value> }
@DBRef
允许通过其 lazy
属性延迟加载。请查看 reference documentation
即将发布的 Spring Data MongoDB 3.3 版本将扩展对 linking 文档的支持以涵盖上述用例。 linked 文档仍然需要单独保存。 @DocumentReference
允许通过 id
属性 link Address
如下所述。
@Document
class Person {
@Id
String id;
@DocumentReference
Address address;
}
{
"_id" : "p1457",
"name" : "...",
"address" : "a4711"
}
@DocumentReference
还将支持 延迟加载 并可用于 link 文档集合。
请查找完整文档 here.
是否有 Spring 数据 Mongo 的模式支持将 link 保存到单独集合中的单独文档,并在其退出时自动重新水合数据库?
@Document
class Person <-- Saves to the Person Collection
@id
UUID id
String name
Address address
@Document
class Address --
@id
UUID id
String address1
...
调用 save(person)
我希望数据库中的地址 属性 反映地址 ID,并将地址对象持久保存到地址集合中。当我把 Person 拉回来时,Address 会完全水合(或者可能是懒惰?)并且可以访问。
- Spring数据Mongo3.1
- Spring 启动 2.4
- Groovy 2.5
- JDK11
在撰写本文时 Spring 数据 MongoDB 3.2 仅支持 link 通过 DBRefs 编辑文档。然而,它们遵循固定结构,因此在目标文档中表示 link 的值看起来像这样
{ "$ref" : <value>, "$id" : <value>, "$db" : <value> }
@DBRef
允许通过其 lazy
属性延迟加载。请查看 reference documentation
即将发布的 Spring Data MongoDB 3.3 版本将扩展对 linking 文档的支持以涵盖上述用例。 linked 文档仍然需要单独保存。 @DocumentReference
允许通过 id
属性 link Address
如下所述。
@Document
class Person {
@Id
String id;
@DocumentReference
Address address;
}
{
"_id" : "p1457",
"name" : "...",
"address" : "a4711"
}
@DocumentReference
还将支持 延迟加载 并可用于 link 文档集合。
请查找完整文档 here.