Docs Menu
Docs Home
/
Relational Migrator
/ /

Atlas Triggers ๋ณ€ํ™˜

์ด ํŽ˜์ด์ง€์˜ ๋‚ด์šฉ

  • ์ด ์ž‘์—…์— ๋Œ€ํ•˜์—ฌ
  • ์‹œ์ž‘ํ•˜๊ธฐ ์ „์—
  • ๋‹จ๊ณ„
  • ์˜ˆ์‹œ
  • ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

์ฟผ๋ฆฌ ๋ณ€ํ™˜๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ SQL Atlas ํŠธ๋ฆฌ๊ฑฐ๋ฅผ ๊ฐ€์ ธ์˜ค๊ณ  MongoDB Atlas Triggers ๋กœ ๋ณ€ํ™˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ฟผ๋ฆฌ ๋ณ€ํ™˜๊ธฐ๋Š” Atlas Triggers๋ฅผ ๋ณ€ํ™˜ํ•  ๋•Œ ํ”„๋กœ์ ํŠธ์— ์ •์˜๋œ SQL ์ฝ”๋“œ์™€ ๊ด€๊ณ„ํ˜• ์Šคํ‚ค๋งˆ๋ฅผ ๊ณ ๋ คํ•ฉ๋‹ˆ๋‹ค.

  • ์ฟผ๋ฆฌ ๋ณ€ํ™˜๊ธฐ๋Š” ๊ธธ๊ฑฐ๋‚˜ ๋ณต์žกํ•œ ์ฟผ๋ฆฌ, ํŠธ๋ฆฌ๊ฑฐ ๋˜๋Š” ์ €์žฅ ํ”„๋กœ์‹œ์ €๋ฅผ ๋ณ€ํ™˜ํ•  ์ˆ˜ ์—†๋Š” AI ๊ธฐ์ˆ ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ผ๋ถ€ ์ฟผ๋ฆฌ๋Š” ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๋ณ€ํ™˜๋˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ๊ณ , ๋‹ค๋ฅธ ์ฟผ๋ฆฌ๋Š” ์ „ํ˜€ ๋ณ€ํ™˜๋˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ์ฟผ๋ฆฌ ๋ณ€ํ™˜๊ธฐ๋Š” ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์˜ ๊ด€๊ณ„ํ˜• ์Šคํ‚ค๋งˆ, MongoDB ์Šคํ‚ค๋งˆ ๋ฐ ๋งคํ•‘ ๊ทœ์น™์„ ์‚ฌ์šฉํ•˜์—ฌ ์ฟผ๋ฆฌ๋ฅผ ๋ณ€ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค. ์ฟผ๋ฆฌ๊ฐ€ ๊ด€๊ณ„ํ˜• ์Šคํ‚ค๋งˆ์— ์—†๋Š” ํ…Œ์ด๋ธ”์„ ์ฐธ๊ณ ํ•˜๊ฑฐ๋‚˜ MongoDB collection์— ๋งคํ•‘๋˜์ง€ ์•Š์€ ํ…Œ์ด๋ธ”์„ ์ฐธ๊ณ ํ•˜๋Š” ๊ฒฝ์šฐ ๋ณ€ํ™˜์ด ์‹คํŒจํ•˜๊ฑฐ๋‚˜ ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ๋ณ€ํ™˜๋œ ์ฟผ๋ฆฌ, ํŠธ๋ฆฌ๊ฑฐ, ๋ทฐ ๋ฐ ์ €์žฅ ํ”„๋กœ์‹œ์ €๋Š” ํ”„๋กœ์ ํŠธ์— ์ €์žฅ๋˜๋ฉฐ ํ”„๋กœ์ ํŠธ ๊ฐ€์ ธ์˜ค๊ธฐ ๋ฐ ๋‚ด๋ณด๋‚ด๊ธฐ๋ฅผ ํ†ตํ•ด ์œ ์ง€๋ฉ๋‹ˆ๋‹ค.

  • SQL ์ฟผ๋ฆฌ๋Š” 40 000 ํ…์ŠคํŠธ ๋ฌธ์ž๋กœ ์ œํ•œ๋ฉ๋‹ˆ๋‹ค.

  • ์™ผ์ชฝ Query Converter ์ฐฝ์—์„œ ์ด์ „ ์ „ํ™˜ ๋‚ด์—ญ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ ๋ณ€ํ™˜์—๋Š” ๋ณ€ํ™˜ ๊ฒฐ๊ณผ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์•„์ด์ฝ˜์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ์ฒด ์˜†์— ์•„์ด์ฝ˜์ด ์—†์œผ๋ฉด ์•„์ง ๋ณ€ํ™˜์ด ์‹œ๋„๋˜์ง€ ์•Š์€ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

    Icon
    ์„ค๋ช…
    Spinner
    ์ด์ œ ๋ณ€ํ™˜์ด ์‹คํ–‰ ์ค‘์ž…๋‹ˆ๋‹ค.
    ๋…น์ƒ‰ ํ™•์ธ ํ‘œ์‹œ
    ์ „ํ™˜์— ์„ฑ๊ณตํ–ˆ์Šต๋‹ˆ๋‹ค.
    ๋นจ๊ฐ„์ƒ‰ ๋Š๋‚Œํ‘œ
    ๋งˆ์ง€๋ง‰ ์‹œ๋„์—์„œ ์ „ํ™˜์ด ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.
  • relational database์—๋Š” ๋ณ€ํ™˜ํ•  trigger๊ฐ€ ํ•˜๋‚˜ ์ด์ƒ ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • ํ”„๋กœ๋•์…˜ ํ™˜๊ฒฝ์— ๋ฐฐํฌํ•˜๊ธฐ ์ „์— ํ•ญ์ƒ ์ฟผ๋ฆฌ ๋ณ€ํ™˜๊ธฐ์—์„œ ์ƒ์„ฑ๋œ ์ฝ”๋“œ๋ฅผ ๊ฒ€ํ† ํ•˜๊ณ  ํ…Œ์ŠคํŠธํ•ฉ๋‹ˆ๋‹ค.

1

Code Generation ํƒญ์—์„œ Query Converter ์ฐฝ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

์ฟผ๋ฆฌ ๋ณ€ํ™˜๊ธฐ์— ์ฒ˜์Œ ์•ก์„ธ์Šคํ•˜๊ฑฐ๋‚˜ ์„ธ์…˜์ด ๋งŒ๋ฃŒ๋œ ๊ฒฝ์šฐ Log In To Use Query Converter ๋ฅผ ํด๋ฆญํ•˜๊ณ  Atlas ์ž๊ฒฉ ์ฆ๋ช…์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

2
  • ํ”„๋กœ์ ํŠธ์—์„œ ์ฟผ๋ฆฌ ๋ณ€ํ™˜๊ธฐ๋ฅผ ์ฒ˜์Œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ Import From Database ์„(๋ฅผ) ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

  • ํ”„๋กœ์ ํŠธ์— ์ด๋ฏธ ๋ณ€ํ™˜๋œ SQL ์ฝ”๋“œ๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ ์™ผ์ชฝ ์ฐฝ์—์„œ Manage Database Objects ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

3
  1. Import Database Objects ๋ชจ๋‹ฌ์—์„œ ๋‹ค์Œ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. Database ์˜†์— ์žˆ๋Š” ์•„์ด์ฝ˜์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

  2. ๋‹ค์Œ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. ์•„์ด์ฝ˜์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

  3. ๋‹ค์Œ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. Triggers ์˜†์— ์žˆ๋Š” ์•„์ด์ฝ˜์ž…๋‹ˆ๋‹ค.

    ํŒ

    ์ „ํ™˜ trigger ๋ฅผ ํ† ๊ธ€ํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. trigger ์ด๋ฆ„ ์˜†์— ์žˆ๋Š” ์•„์ด์ฝ˜์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. ๋ชจ๋“  ํŠธ๋ฆฌ๊ฑฐ๊ฐ€ ๊ธฐ๋ณธ๊ฐ’ ์„ ํƒ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

  4. Save๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

    ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์Šคํ‚ค๋งˆ์˜ ๊ฐ trigger์— ๋Œ€ํ•œ ์ฝ”๋“œ๋ฅผ ํ”„๋กœ์ ํŠธ๋กœ ๊ฐ€์ ธ์˜ค๊ณ  ์™ผ์ชฝ Query Converter ์ฐฝ์˜ Triggers ์•„๋ž˜์— ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

4
  1. ์™ผ์ชฝ ์ฐฝ Triggers ์•„๋ž˜์—์„œ ํŠธ๋ฆฌ๊ฑฐ ์ด๋ฆ„์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

    ํŒ

    Filter ํ…์ŠคํŠธ ์ƒ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ์ฒด ์ด๋ฆ„๊ณผ SQL ๊ตฌ๋ฌธ์„ ๊ธฐ์ค€์œผ๋กœ ์ฟผ๋ฆฌ, ์ €์žฅ ํ”„๋กœ์‹œ์ €, ํŠธ๋ฆฌ๊ฑฐ ๋ฐ ๋ทฐ๋ฅผ ํ•„ํ„ฐ๋งํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    SQL ํŠธ๋ฆฌ๊ฑฐ ์ฝ”๋“œ๊ฐ€ Imported Trigger ์ฐฝ์— ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

  2. Convert ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. ์ฟผ๋ฆฌ ๋ณ€ํ™˜๊ธฐ๊ฐ€ ์ฝ”๋“œ๋ฅผ ๋ณ€ํ™˜ํ•  ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆฝ๋‹ˆ๋‹ค.

    ๋ณ€ํ™˜๋œ MongoDB ์ฝ”๋“œ๊ฐ€ Converted MongoDB Query ์ฐฝ์— ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

    ์ฟผ๋ฆฌ ๋ณ€ํ™˜๊ธฐ์— ์˜ค๋ฅ˜๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ Converted MongoDB Query ์ฐฝ์—์„œ ์„ธ๋ถ€ ์ •๋ณด๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  3. ๋‹ค์Œ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. Converted MongoDB Query ์ฐฝ์˜ ์•„์ด์ฝ˜์„ ํด๋ฆญํ•˜์—ฌ MongoDB ์ฝ”๋“œ๋ฅผ ํด๋ฆฝ๋ณด๋“œ์— ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค.

5
  1. Atlas ๊ณ„์ •์— ๋กœ๊ทธ์ธํ•ฉ๋‹ˆ๋‹ค.

  2. Overview ํ™”๋ฉด์—์„œ Triggers ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

  3. Add Trigger๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

    ํŒ

    ๋ณ€ํ™˜๋œ MongoDB ์ฝ”๋“œ์—๋Š” Atlas์—์„œ trigger๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด ์„ ํƒํ•ด์•ผ ํ•˜๋Š” ๋ชจ๋“  ๋ณ€์ˆ˜์— ๋Œ€ํ•œ ์ฃผ์„ ์ค„์ด ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

    // Collection Name: products
    // Operation Type: Insert
  4. Name ํ…์ŠคํŠธ ํ•„๋“œ์— trigger ์ด๋ฆ„์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

  5. Cluster Name, Database Name ๋ฐ Collection Name ๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  6. Operation Type ์„ Insert Document ์œผ๋กœ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  7. Document Preimage ๋ฐ Full Document ์Šค์œ„์น˜๋ฅผ ์ผœ์ง์œผ๋กœ ์ „ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

  8. Function ํ…์ŠคํŠธ ํ•„๋“œ์— ๋ณ€ํ™˜๋œ MongoDB ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

    ์ค‘์š”

    ์ƒ์„ฑ๋œ Atlas ์ฝ”๋“œ์—์„œ clusterName ๋ฐ databaseName ๋ฅผ cluster ๋ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ด๋ฆ„๊ณผ ์ผ์น˜ํ•˜๋„๋ก ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.

  9. Save ์„ ํด๋ฆญํ•˜์—ฌ Realm ํŠธ๋ฆฌ๊ฑฐ๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ ์˜ˆ์ œ๋Š” Atlas์— ๋Œ€ํ•œ MySQL trigger ๋ณ€ํ™˜๊ธฐ๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

CREATE TRIGGER TRIGGER_UPPER_PRODUCTS
BEFORE INSERT
ON MYDATABASE.PRODUCTS
FOR EACH ROW
SET NEW.FULL_NAME = UPPER(new.FULL_NAME)
// The relational database trigger has been converted to MongoDB Atlas Triggers format.
// To create a trigger, open your Atlas project (https://cloud.mongodb.com) and choose Triggers
// For more on Atlas triggers see the docs: https://www.mongodb.com/ko-kr/docs/atlas/triggers/
// Create your trigger using the following settings and paste the code into the Function section:
// Watch Against: Collection
// Cluster Name: Ensure clusterName matches selection in Atlas Trigger configuration
// Database Name: Ensure databaseName matches selection in Atlas Trigger configuration
// Collection Name: products
// Operation Type: Insert
// Full Document: On
// Document Preimage: Off
exports = async function(changeEvent) {
const clusterName = "clusterName";
const databaseName = "databaseName";
const { fullDocument } = changeEvent;
const db = context.services.get(clusterName).db(databaseName);
const collection = db.collection('products');
if (fullDocument && fullDocument.fullName) {
fullDocument.fullName = fullDocument.fullName.toUpperCase();
await collection.updateOne({ _id: fullDocument._id }, { $set: { fullName: fullDocument.fullName } });
}
};
  • ๋ทฐ ๋ณ€ํ™˜

  • ์ฟผ๋ฆฌ ๋ณ€ํ™˜

  • ์ €์žฅ ํ”„๋กœ์‹œ์ € ๋ณ€ํ™˜

๋Œ์•„๊ฐ€๊ธฐ

์ €์žฅ ํ”„๋กœ์‹œ์ € ๋ณ€ํ™˜