Model One-to-One Relationships with Embedded Documents
来源:互联网 发布:数据分析员的岗位职责 编辑:程序博客网 时间:2024/05/18 03:38
Model One-to-One Relationships with Embedded Documents
On this page
- Overview
- Pattern
Overview
Data in MongoDB has a flexible schema. Collections do not enforce document structure. Decisions that affect how you model data can affect application performance and database capacity. See Data Modeling Conceptsfor a full high level overview of data modeling in MongoDB.
This document describes a data model that uses embedded documents to describe relationships between connected data.
Pattern
Consider the following example that maps patron and address relationships. The example illustrates the advantage of embedding over referencing if you need to view one data entity in context of the other. In this one-to-one relationship between patron
and address
data, the address
belongs to the patron
.
In the normalized data model, the address
document contains a reference to the patron
document.
{ _id: "joe", name: "Joe Bookreader"}{ patron_id: "joe", street: "123 Fake Street", city: "Faketon", state: "MA", zip: "12345"}
If the address
data is frequently retrieved with the name
information, then with referencing, your application needs to issue multiple queries to resolve the reference. The better data model would be to embed the address
data in the patron
data, as in the following document:
{ _id: "joe", name: "Joe Bookreader", address: { street: "123 Fake Street", city: "Faketon", state: "MA", zip: "12345" }}
With the embedded data model, your application can retrieve the complete patron information with one query.
- Model One-to-One Relationships with Embedded Documents
- Model One-to-Many Relationships with Embedded Documents
- Model One-to-Many Relationships with Document References
- How to define One-Many and One-One relationships
- Google advances AI with ‘one model to learn them all
- one to one
- Hibernate one-to-one
- hibernate :one-to-one
- 一对一 one-to-one
- hibernate:one-to-one
- one-to-one 映射
- one-to-one
- Hibernate One to One
- use mongoose to update documents with model and Schema
- CoreDataErrorThe model used to open the store is incompatible with the one used to create the store
- The model used to open the store is incompatible with the one used to create the store错误
- The model used to open the store is incompatible with the one used to create the store
- The model used to open the store is incompatible with the one used to create the store
- 聊天机器人教学:使用Dialogflow (API.AI)开发 iOS Chatbot App
- RAC 简单举例 注册按钮
- 3.1(2)
- 使用Python解析MNIST数据集(IDX文件格式)
- 函数式编程@FunctionalInterface
- Model One-to-One Relationships with Embedded Documents
- Deep Reinforcement Learning for Dialogue Generation阅读笔记
- 桌面系统(web前端)jQuery制作Web桌面系统界面类似WebQQ桌面布局
- Kafka 介绍
- python实用工具集
- java-Collection(Set)
- 职业分类明细1.0
- 贫血模型和充血模型
- eclipse的下载与安装