Archive

[TIL220220] MongoDB 사용

manon_e 2022. 2. 21. 19:50
반응형

 

 

계정 생성 후  Network / Database Access 완료 후 Connect

 

 

Connet - Connet your application
code 복사해서 연결하기

 

 

 

작업환경에서 mongodb 설치

npm i mongodb

 

 

MongoClient.connet('주소')

username과 password 변경

import { MongoClient } from "mongodb";

async export default function handler(req, res) {
  if (req.method === "POST") {
    const data = req.body;

    const { title, image, address, description } = data;
    await MongoClient.connect(
      'mongodb+srv://abd:<password>@cluster0.6baoc.mongodb.net/myFirstDatabase?
      retryWrites=true&w=majority'
    );
  }
}

 

PW 자동생성하여 붙여넣기

async export default function handler(req, res) {
  if (req.method === "POST") {
    const data = req.body;

    const { title, image, address, description } = data;
    await MongoClient.connect(
       //id,PW, db name 변경
      'mongodb+srv://abd:ehM3Cr1mwMbDoWg3@cluster0.6baoc.mongodb.net/meetups?
      retryWrites=true&w=majority'
    );
  }
}

 

반응형

'Archive' 카테고리의 다른 글

[Next.JS] Next 기초 개념 Pre-rendering (CSR/SSR)  (0) 2022.02.26
[TIL220221] SDK / API  (0) 2022.02.21
[Next.JS] Dynamic Routes  (0) 2022.02.15
[Redux] Redux & Redux-toolkit  (0) 2022.02.13
[TIL220128] Image uploader  (0) 2022.01.28