์˜ค๋Š˜์˜ TIL๐Ÿ‘ฉโ€๐ŸŒพ

Let's TECH๐Ÿงยท2021๋…„ 9์›” 28์ผ
0

Today I Learned

๋ชฉ๋ก ๋ณด๊ธฐ
1/6
post-thumbnail

โœMongoDB ์ ‘์† ์—๋Ÿฌ

์›์ธ

Mongodb ๊ณ„์ • ๋น„๋ฐ€๋ฒˆํ˜ธ์— ํฌํ•จ๋œ ํŠน์ˆ˜๋ฌธ์ž๊ฐ€ ์ธ์ฝ”๋”ฉ๋˜๋ฉด์„œ ๋ฐœ์ƒํ•œ ์—๋Ÿฌ

์—๋Ÿฌ ๋กœ๊ทธ

npm run dev

> nextjs-course@0.1.0 dev C:\Users\์ด๋ฏผ์ฃผ\Desktop\coding\nextjs-course
> next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
event - compiled successfully
event - build page: /next/dist/pages/_error
wait  - compiling...
event - compiled successfully
event - build page: /new-meetup
wait  - compiling...
event - compiled successfully
event - build page: /api/new-meetup
wait  - compiling...
event - compiled successfully
error - MongoAPIError: URI must include hostname, domain name, and tld
    at Object.resolveSRVRecord (C:\Users\์ด๋ฏผ์ฃผ\Desktop\coding\nextjs-course\node_modules\mongodb\lib\connection_string.js:51:25)
    at Object.connect (C:\Users\์ด๋ฏผ์ฃผ\Desktop\coding\nextjs-course\node_modules\mongodb\lib\operations\connect.js:41:36)
    at C:\Users\์ด๋ฏผ์ฃผ\Desktop\coding\nextjs-course\node_modules\mongodb\lib\mongo_client.js:127:23
    at Object.maybePromise (C:\Users\์ด๋ฏผ์ฃผ\Desktop\coding\nextjs-course\node_modules\mongodb\lib\utils.js:518:5)
    at MongoClient.connect (C:\Users\์ด๋ฏผ์ฃผ\Desktop\coding\nextjs-course\node_modules\mongodb\lib\mongo_client.js:126:24)
    at Function.connect (C:\Users\์ด๋ฏผ์ฃผ\Desktop\coding\nextjs-course\node_modules\mongodb\lib\mongo_client.js:190:36)
    at handler (C:\Users\์ด๋ฏผ์ฃผ\Desktop\coding\nextjs-course\.next\server\pages\api\new-meetup.js:27:75)
    at Object.apiResolver (C:\Users\์ด๋ฏผ์ฃผ\Desktop\coding\nextjs-course\node_modules\next\dist\server\api-utils.js:101:15)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async DevServer.handleApiRequest (C:\Users\์ด๋ฏผ์ฃผ\Desktop\coding\nextjs-course\node_modules\next\dist\server\next-server.js:770:9) {
  page: '/api/new-meetup'
}

ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

๋น„๋ฐ€๋ฒˆํ˜ธ์— ์žˆ๋Š” ํŠน์ˆ˜๋ฌธ์ž ์‚ญ์ œ

์ฐธ๊ณ ๊ธ€

https://stackoverflow.com/questions/55753484/mongoparseerror-uri-does-not-have-hostname-domain-name-and-tld/56705563

๐Ÿ™๋˜ ๋‹ค๋ฅธ ์—๋Ÿฌ ๋ฐœ์ƒ

์›์ธ

์นดํŽ˜์—์„œ ์ง„ํ–‰ํ–ˆ๋˜ ์ž‘์—…์„ ์ง‘์— ์™€์„œ ํ•˜๋ ค๊ณ  ํ•˜๋‹ˆ๊นŒ Mongodb์™€ ์—ฐ๊ฒฐ๋œ ip ์ฃผ์†Œ๊ฐ€ ๋‹ฌ๋ผ์„œ ์ƒ๊ธด ๋ฌธ์ œ

์—๋Ÿฌ ๋กœ๊ทธ

MongoServerSelectionError: connection to 34.204.20.102:27017 closed

ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

์ง‘ ip์ฃผ์†Œ๋กœ ๋ณ€๊ฒฝ, 0.0.0.0/0 ip์ฃผ์†Œ ์ถ”๊ฐ€

์ฐธ๊ณ ๊ธ€

https://stackoverflow.com/questions/60431996/mongooseerror-mongooseserverselectionerror-connection-monitor-to-52-6-250-2/60863977

๐Ÿ™๋˜ ๋‹ค๋ฅธ ์—๋Ÿฌ ๋ฐœ์ƒ

์—๋Ÿฌ ๋กœ๊ทธ

error - TypeError: Cannot create property '_id' on string '{"title":"title","image":"https://mblogthumb-phinf.pstatic.net/20160221_113/moisophiaj_1456039384605ruhmX_JPEG/%BA%D0%C0%A7%B1%E2_%C0%D6%B4%C2_%BF%B9%BB%DB_%BF%DC%B1%B9_%B5%B5%BD%C3_%C7%B3%B0%E6_%BB%E7%C1%F8_%288%29.jpg?type=w2","address":"add","description":"desc"}'

ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

headers์—์„œ 'Accept'๋กœ ๋˜์–ด์žˆ๋˜ ๋ถ€๋ถ„์„ 'Content-Type'์œผ๋กœ ์ˆ˜์ •

function NewMeetupPage() {
  async function addMeetupHandler(enteredMeetupData) {
    const response = await fetch('/api/new-meetup', {
      method: 'POST',
      body: JSON.stringify(enteredMeetupData),
      headers: {
        'Content-Type': 'application/json' // 'Accept'๋กœ ๋˜์–ด์žˆ๋˜ ๋ถ€๋ถ„์„ 'Content-Type'์œผ๋กœ ์ˆ˜์ •
      }
    });

๐Ÿ‘Š๋ฌธ์ œ ํ•ด๊ฒฐ ์™„๋ฃŒ

npm run dev

> nextjs-course@0.1.0 dev C:\Users\์ด๋ฏผ์ฃผ\Desktop\coding\nextjs-course
> next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
event - compiled successfully
event - build page: /next/dist/pages/_error
wait  - compiling...
event - compiled successfully
event - build page: /new-meetup
wait  - compiling...
event - compiled successfully
wait  - compiling...
event - compiled successfully
wait  - compiling...
event - compiled successfully
event - build page: /api/new-meetup
wait  - compiling...
event - compiled successfully
{
  acknowledged: true,
  insertedId: new ObjectId("615266200d0f787f773a2b7b")
}
{
  acknowledged: true,
  insertedId: new ObjectId("615266250d0f787f773a2b7c")
}
{
  acknowledged: true,
  insertedId: new ObjectId("6152662e0d0f787f773a2b7d")
}
wait  - compiling...
event - compiled successfully

์ •์ƒ์ ์œผ๋กœ ๋ฐ์ดํ„ฐ๊ฐ€ insert๋จ

profile
Minju's Tech Blog

0๊ฐœ์˜ ๋Œ“๊ธ€