[MongoDB] Model Relationships Between Documents (3)
publisher ์ ๋ณด๊ฐ ๋ฐ๋ณต๋๊ณ ์๋ค.
{
title: "MongoDB: The Definitive Guide",
author: [ "Kristina Chodorow", "Mike Dirolf" ],
published_date: ISODate("2010-09-24"),
pages: 216,
language: "English",
publisher: {
name: "O'Reilly Media",
founded: 1980,
location: "CA"
}
}
{
title: "50 Tips and Tricks for MongoDB Developer",
author: "Kristina Chodorow",
published_date: ISODate("2011-05-06"),
pages: 68,
language: "English",
publisher: {
name: "O'Reilly Media",
founded: 1980,
location: "CA"
}
}
์ด๋ฅผ ํด๊ฒฐ ํ๊ธฐ ์ํด์, referencing์ ์ฌ์ฉํ๋๋ฐ,
๊ฐ publisher๊ฐ ๋ธ ์ฑ ์ ์๊ฐ ์ ๊ณ , ํ ์ฌ๋์ด ๋ผ ์ ์๋ ์ฑ ์ ์์ ํ๊ณ๊ฐ ์๋ค๋ฉด,
publisher document์์ book reference๋ฅผ ๋ฃ๋ ๊ฒ์ด ํจ๊ณผ์ ์ด๋ค.
// publisher document
{
name: "O'Reilly Media",
founded: 1980,
location: "CA",
books: [123456789, 234567890, ...]
}
// book document
{
_id: 123456789,
title: "MongoDB: The Definitive Guide",
author: [ "Kristina Chodorow", "Mike Dirolf" ],
published_date: ISODate("2010-09-24"),
pages: 216,
language: "English"
}
{
_id: 234567890,
title: "50 Tips and Tricks for MongoDB Developer",
author: "Kristina Chodorow",
published_date: ISODate("2011-05-06"),
pages: 68,
language: "English"
}
๊ทธ๋ ์ง ์๋ค๋ฉด,
๊ฐ ์ฑ ์ publisher_id๋ก referenceํ ์ ์๋๋ก ํ๋ ๊ฒ์ด ํจ๊ณผ์ ์ด๋ค.
{
_id: "oreilly",
name: "O'Reilly Media",
founded: 1980,
location: "CA"
}
{
_id: 123456789,
title: "MongoDB: The Definitive Guide",
author: [ "Kristina Chodorow", "Mike Dirolf" ],
published_date: ISODate("2010-09-24"),
pages: 216,
language: "English",
publisher_id: "oreilly"
}
{
_id: 234567890,
title: "50 Tips and Tricks for MongoDB Developer",
author: "Kristina Chodorow",
published_date: ISODate("2011-05-06"),
pages: 68,
language: "English",
publisher_id: "oreilly"
}
| [Javascript] Event Loop์ Call Stack โญ (0) | 2021.06.22 |
|---|---|
| [React] Virtual-DOM, Reconciliation, fiber (0) | 2021.06.21 |
| [MongoDB] Model Relationships Between Documents (2) (0) | 2021.06.10 |
| [MongoDB] Model Relationships Between Documents (1) (0) | 2021.06.10 |
| [React] Fetch data in React (2)๐ฆ (0) | 2021.05.27 |