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'
}
๋น๋ฐ๋ฒํธ์ ์๋ ํน์๋ฌธ์ ์ญ์
์นดํ์์ ์งํํ๋ ์์ ์ ์ง์ ์์ ํ๋ ค๊ณ ํ๋๊น Mongodb์ ์ฐ๊ฒฐ๋ ip ์ฃผ์๊ฐ ๋ฌ๋ผ์ ์๊ธด ๋ฌธ์
MongoServerSelectionError: connection to 34.204.20.102:27017 closed
์ง ip์ฃผ์๋ก ๋ณ๊ฒฝ, 0.0.0.0/0 ip์ฃผ์ ์ถ๊ฐ
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๋จ