๋ฌธ์ ํ โ Atlas App Services
๊ด๊ณ
์ด ํ์ด์ง์ ๋ด์ฉ
๊ฐ์
๊ด๊ณ๋ ๋ ๋ฌธ์ ์ฌ์ด์ ์ฐ๊ฒฐ์ ๋๋ค. ๊ด๊ณ๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฌธ์๊ฐ ๋ณ๋์ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ ์ปฌ๋ ์ ์ ์๋ ๊ฒฝ์ฐ์๋ ์ฝ๊ธฐ ๋ฐ ์ฐ๊ธฐ ์์ ์์ ๊ด๋ จ ๋ฌธ์๋ฅผ ์ฐธ์กฐํ๊ณ ์ฟผ๋ฆฌํ ์ ์์ต๋๋ค.
'์์ค' MongoDB ์ปฌ๋ ์ ์ ๋ํ ๊ด๊ณ๋ฅผ ์ ์ํ๊ณ '์ธ๋ถ' ์ปฌ๋ ์ ์ ๋ฌธ์์ ์ฐ๊ฒฐํฉ๋๋ค. Atlas App Services๋ ์์ค ํ๋์ ๊ฐ์ ์ฐธ์กฐํ๋ ์ธ๋ถ ๋ฌธ์๋ก ๋์ฒดํ์ฌ ๋๊ธฐํ๋ SDK ๋ฐ์ดํฐ ๋ชจ๋ธ์ ๊ด๊ณ๋ฅผ ์๋์ผ๋ก ํ์ธํฉ๋๋ค.
๊ด๊ณ๋ ๋จ๋ฐฉํฅ์ด๋ฉฐ ๊ณ ์ ์ฑ์ด๋ ๊ธฐํ ์ธ๋ถ ํค ์ ์ฝ ์กฐ๊ฑด์ ์ ์ฉํ์ง ์์ต๋๋ค. ์์ค ํ๋์์ ์กด์ฌํ์ง ์๋ ์ธ๋ถ ๊ฐ์ ์ฐธ์กฐํ๋ ๊ฒฝ์ฐ App Services๋ ํ์ธ๋ ๊ด๊ณ์์ ์ฐธ์กฐ๋ฅผ ์๋์ผ๋ก ์๋ตํฉ๋๋ค.
์์
๋ ๊ฐ์ ์ปฌ๋ ์ ์ด ์๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ์๋ก ๋ค์ด ๋ณด๊ฒ ์ต๋๋ค:
accounts
์ปฌ๋ ์ ์๋ ๊ฐ๊ฐ ๊ณ ๊ฐ ๊ณ์ ์ ์ค๋ช ํ๋ ๋ฌธ์๊ฐ ํฌํจ๋์ด ์์ต๋๋ค.๊ณ์ ์ปฌ๋ ์ ์คํค๋ง{ "title": "Account", "properties": { "_id": { "bsonType": "objectId" }, "account_id": { "bsonType": "string" }, "products": { "bsonType": "array", "items": { "bsonType": "string" } }, ... } } customers
์ปฌ๋ ์ ์๋ ๊ฐ๊ฐ ํ๋ ์ด์์ ๊ณ์ ์ ๊ฐ์ง ์ ์๋ ๋จ์ผ ๊ณ ๊ฐ์ ์ค๋ช ํ๋ ๋ฌธ์๊ฐ ํฌํจ๋์ด ์์ต๋๋ค.customers
์ปฌ๋ ์ ์ ๋ชจ๋ ๋ฌธ์์๋ ๊ณ ๊ฐ์๊ฒ ์ ์ฉ๋๋accounts
์ปฌ๋ ์ ์ ๋ชจ๋account_id
๊ฐ์ ๋ฐฐ์ด์ด ํฌํจ๋accounts
ํ๋๊ฐ ์์ต๋๋ค.๊ณ ๊ฐ ์ปฌ๋ ์ ์คํค๋ง{ "title": "Customer", "properties": { "username": { "bsonType": "string" }, "accounts": { "bsonType": "array", "items": { "bsonType": "string" } }, ... } }
์ฑ์ customers
์ปฌ๋ ์
์์ ์ด ๊ด๊ณ๋ฅผ ์ ์ํฉ๋๋ค. accounts
ํ๋์ ์ ์ฅ๋ ๊ณ์ ID ๊ฐ ๋ฐฐ์ด์์ accounts
์ปฌ๋ ์
์ ์๋ ๊ฐ ๋ฌธ์์ account_id
ํ๋๋ฅผ ๊ฐ๋ฆฌํต๋๋ค.
{ "accounts": { "ref": "#/relationship/mongodb-atlas/sample_analytics/accounts", "foreign_key": "account_id", "is_list": true } }
์ด ๊ด๊ณ๊ฐ ์ ์๋๋ฉด App Services๋ ํด๋ผ์ด์ธํธ ์ฟผ๋ฆฌ์์ ๊ณ ๊ฐ๊ณผ ํด๋น ๊ณ ๊ฐ์ ๋ชจ๋ ๊ณ์ ์ ๋ฐํํ ์ ์์ต๋๋ค. ๊ด๊ณ๊ฐ ์์ผ๋ฉด ์ฟผ๋ฆฌ๋ ์ ์ฒด Account
๊ฐ์ฒด ๋์ account_id
๊ฐ ๋ชฉ๋ก๋ง ๋ฐํํฉ๋๋ค.
์นด๋๋๋ฆฌํฐ
๊ด๊ณ์ ์นด๋๋๋ฆฌํฐ์ ๋ฐ๋ผ ์ฐธ์กฐํ ์ ์๋ ์ธ๋ถ ๋ฌธ์์ ์๊ฐ ๊ฒฐ์ ๋ฉ๋๋ค. App Services๋ 'to-one' ๋ฐ 'to-many', ์ด๋ ๊ฒ ๋ ๊ฐ์ง ๊ด๊ณ ์นด๋๋๋ฆฌํฐ๋ฅผ ์ง์ํฉ๋๋ค.
To-One
'to-one' ๊ด๊ณ๋ ๊ฐ ์์ค ๋ฌธ์๋ฅผ ๋จ์ผ ๋ฌธ์ ๋๋ ์ธ๋ถ ์ปฌ๋ ์ ์ ๋ฌธ์ ๋ฐฐ์ด๊ณผ ์ฐ๊ฒฐํฉ๋๋ค.
๊ด๊ณ์ 'to-one' ์นด๋๋๋ฆฌํฐ๊ฐ ์์์ ๋ํ๋ด๋ ค๋ฉด is_list
๋ฅผ false
๋ก ์ค์ ํฉ๋๋ค.
{ "owner": { "ref": "#/relationship/mongodb-atlas/example/people", "foreign_key": "_id", "is_list": false } }
App Services๋ ์์ค ๊ฐ์ ์ฐธ์กฐ๋ ๊ฐ์ฒด ๋๋ SDK ๋ชจ๋ธ์ null ๊ฐ์ผ๋ก ์๋์ผ๋ก ๋ฐ๊ฟ๋๋ค.
{ "name": "Pet", "properties": { "name": "string", "owner": "Person" } } { "name": "Person", "properties": { "name": "string" } }
To-Many
'to-many' ๊ด๊ณ๋ ๊ฐ ์์ค ๋ฌธ์๋ฅผ ์ธ๋ถ ์ปฌ๋ ์ ์ ๋ฌธ์ ๋ชฉ๋ก๊ณผ ์ฐ๊ฒฐํฉ๋๋ค.
๊ด๊ณ์ 'to-many' ์นด๋๋๋ฆฌํฐ๊ฐ ์์์ ๋ํ๋ด๋ ค๋ฉด is_list
๋ฅผ true
๋ก ์ค์ ํฉ๋๋ค:
{ "pets": { "ref": "#/relationship/mongodb-atlas/example/pets", "foreign_key": "_id", "is_list": true } }
App Services๋ ์์ค ๊ฐ์ ์ฐธ์กฐ๋ ๊ฐ์ฒด ๋๋ SDK ๋ชจ๋ธ์ null ๊ฐ์ผ๋ก ์๋์ผ๋ก ๋ฐ๊ฟ๋๋ค.
{ "name": "Pet", "properties": { "name": "string" } } { "name": "Person", "properties": { "name": "string", "pets": "Pet[]" } }
๋ด์ฅ๋ ๊ฐ์ฒด ๊ด๊ณ
๋ด์ฅ๋ ๊ฐ์ฒด๋ ์ธ๋ถ ์ปฌ๋ ์ ๊ณผ ๊ด๊ณ๋ฅผ ๊ฐ์ง ์ ์์ต๋๋ค. ์ ํ๊ธฐ๋ฒ์ ์ฌ์ฉํ์ฌ ๋ด์ฅ๋ ๊ฐ์ฒด์ ์์ฑ์ ์ก์ธ์คํฉ๋๋ค.
๋ค๋ฅธ ์ปฌ๋ ์ ์ ๋ด์ฅ๋ ๊ฐ์ฒด
๋ด์ฅ๋ ๊ฐ์ฒด๋ ์ธ๋ถ ์ปฌ๋ ์ ์ ๊ฐ์ฒด์ ๊ด๊ณ๋ฅผ ๊ฐ์ง ์ ์์ต๋๋ค.
{ "title": "Person", "properties": { "_id": { "bsonType": "objectId" }, "pet": { "bsonType":"object", "properties": { "favoriteToyBrand": { "bsonType": "objectId" } } } // ...additional model properties } }
์ ํ๊ธฐ๋ฒ์ ์ฌ์ฉํ์ฌ ์ธ๋ถ ์ปฌ๋ ์ ๊ณผ ๊ด๊ณ๊ฐ ์๋ ๋ด์ฅ๋ ๊ฐ์ฒด ์์ฑ์ ์ง์ ํฉ๋๋ค. ๊ทธ๋ฐ ๋ค์ ์ธ๋ถ ์ปฌ๋ ์ ์ธ๋ถ ์ ๋ณด ๋ฐ ์ธ๋ถ ํค ํ๋๋ฅผ ์ง์ ํ ์ ์์ต๋๋ค.
{ "pet.favoriteToyBrand": { "ref": "#/relationship/mongodb-atlas/example/ToyBrand", "foreign_key": "_id", "is_list": false } }
๋ชฉ๋ก์ ๋ด์ฅ๋ ๊ฐ์ฒด
๋ชฉ๋ก ์์ฑ ๋ด์ ๋ด์ฅ๋ ๊ฐ์ฒด๋ ์ธ๋ถ ์ปฌ๋ ์ ๊ณผ ๊ด๊ณ๋ฅผ ๊ฐ์ง ์ ์์ต๋๋ค.
{ "title": "Person", "properties": { "_id": { "bsonType": "objectId" }, "pets": { "bsonType":"array", "items": { "bsonType": "object", "properties": { "favoriteToyBrand": { "bsonType": "objectId" } } } } // ...additional model properties } }
๋ชฉ๋ก์ ํฌํจ๋ ๋ด์ฅ๋ ๊ฐ์ฒด ์์ฑ์ ์ก์ธ์คํ๋ ค๋ฉด ๋ค์์ ์ฌ์ฉํฉ๋๋ค: field1.[].field2
(์: pets.[].favoriteToyBrand
). ์ฌ๊ธฐ์์ ์ธ๋ถ ์ปฌ๋ ์
์ธ๋ถ ์ ๋ณด ๋ฐ ์ธ๋ถ ํค ํ๋๋ฅผ ์ง์ ํ ์ ์์ต๋๋ค.
ํ
์ฌ์ ๊ณผ ์ธํธ์ ๋์ผํ ๊ตฌ๋ฌธ ์ฌ์ฉ
์ฌ์ ๋ฐ ์ธํธ ๋ด์์ ๊ด๊ณ๋ฅผ ์์ฑํ ๋ ์ด์ ๋์ผํ field1.[].field2
๊ตฌ๋ฌธ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
{ "pets.[].favoriteToyBrand": { "ref": "#/relationship/mongodb-atlas/example/ToyBrand", "foreign_key": "_id", "is_list": false } }
์ฐธ๊ณ
๊ด๊ณ ๋ด ๊ธฐ๋ณธ(Primitives) vs ๋ชฉ๋ก, ์ฌ์ ๋ฐ ์ธํธ
์์ ์์์๋ is_list
๊ฐ false๋ก ์ค์ ๋์ด ์์ต๋๋ค. ์ฌ๊ธฐ์ ๊ด๊ณ ๋ฌธ์์ด์ ๋์ ์๋ ํ๋๋ ๋ชฉ๋ก์ด ์๋ ๊ธฐ๋ณธ(primitive) ํ๋์
๋๋ค. ๋ด์ฅ๋ ๊ฐ์ฒด๊ฐ ๋ชฉ๋ก์ ํฌํจ๋์ด ์์ง๋ง favoriteToyBrand
์์ฑ ์์ฒด๋ ์ฌ์ , ์งํฉ ๋๋ ๋ชฉ๋ก์ด ์๋๋๋ค.
๊ด๊ณ ์ ์
๊ด๊ณ๋ฅผ ์ ์ํ ๋๋ ์ด๋ฌํ ์ ํ ์ฌํญ์ ์ผ๋์ ๋์ธ์:
์ฐธ์กฐ ํ๋์ ํ์ฉ๋์ง ์๋ ํญ๋ชฉ
_id
์ฐธ์กฐ ํ๋๋
required
ํ๋๊ฐ ์๋์ด์ผ ํฉ๋๋ค.์ธ๋ถ ํค๋ ํ๋๊ฐ ์ฐธ์กฐํ๋ ์ปฌ๋ ์ ์
_id
ํ๋์ฌ์ผ ํฉ๋๋ค.
1. ์คํค๋ง ์ ์
๊ด๊ณ๋ฅผ ์ ์ํ๋ ค๋ฉด ์์ค ์ปฌ๋ ์ ๊ณผ ์ธ๋ถ ์ปฌ๋ ์ ๋ชจ๋์ ๋ํด ์ ์๋ ์คํค๋ง๊ฐ ์์ด์ผ ํฉ๋๋ค. ์คํค๋ง๋ฅผ ์ ์ํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด๋ ค๋ฉด ์คํค๋ง ์ ์ฉ์ ์ฐธ์กฐํ์ธ์.
2. ์ ๊ด๊ณ ๋ง๋ค๊ธฐ
์คํค๋ง์ ํจ๊ป ์ฐ๊ฒฐ๋ MongoDB ๋ฐ์ดํฐ ์์ค์์ ์ปฌ๋ ์ ์ ๋ํ ๊ด๊ณ๋ฅผ ์ ์ํฉ๋๋ค.
3. ๊ด๊ณ ๊ตฌ์ฑ
๊ด๊ณ ์ ์๋ ์์ค ์ปฌ๋ ์ ์ ์คํค๋ง์ ํฌํจ๋ ํ๋๋ฅผ ๋งคํํ๊ณ ์ธ๋ถ ์ปฌ๋ ์ ์คํค๋ง์ ์๋ ๋์ผํ ์ ํ์ ํ๋๋ฅผ ๊ฐ๋ฆฌํต๋๋ค.