MongoDB Atlas ์ฟผ๋ฆฌ
Atlas Device Sync, ๋ฐ์ดํฐ API ๋ฐ HTTPS Endpoints๋ ๋ ์ด์ ์ง์๋์ง ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ ์ง์ ์ค๋จ ํ์ด์ง๋ฅผ ์ฐธ์กฐํ์ธ์.
๋ด์ฅ ๋ฐ์ดํฐ ์์ค ํด๋ผ์ด์ธํธ ๋ฅผ ์ฌ์ฉํ์ฌ ํจ์์์ ์ฐ๊ฒฐ๋ MongoDB ๋ฐ์ดํฐ ์์ค ์ ๋ฐ์ดํฐ๋ก ์์ ํ ์ ์์ต๋๋ค. ํด๋ผ์ด์ธํธ ์๋ ๋ฐ์ดํฐ๋ฅผ ์ฝ๊ณ , ์ฐ๊ธฐ (write), ์ง๊ณํ ์ ์๋ ๋ฉ์๋๊ฐ ํฌํจ๋์ด ์์ต๋๋ค.
ํจ์์์ ๋ฐ์ดํฐ ์์ค๋ก ์์ ํ๋ ๋ฐฉ๋ฒ์ ๋ํ ์๋ ๋ค์ ๊ฐ์ด๋๋ฅผ ์ฐธ์กฐํ์ธ์:.
์ฌ์ฉ ๊ฐ๋ฅํ ์ฟผ๋ฆฌ ๋ฐ ์ง๊ณ ๋ฉ์๋์ ๋ํ ์์ธํ ์ฐธ์กฐ ์ ๋ณด๋ MongoDB API ์ฐธ์กฐ๋ฅผ ์ฐธ์กฐํ์ธ์.
exports = async function() { // 1. Get a data source client const mongodb = context.services.get("mongodb-atlas"); // 2. Get a database & collection const db = mongodb.db("myDatabase") const collection = db.collection("myCollection") // 3. Read and write data with MongoDB queries await collection.insertOne({ text: "Hello, world!", author: context.user.id }) return await collection.findOne({ author: context.user.id }) }