I am currently using Next.js v13. I can get data from api in first attempt. But If I make a change in code, then this error occurs.
My api:
import connectMongo from "@/lib/connectMongo"
import Book from "@/models/Book.js"
import { NextResponse } from "next/server"
export const config = {
api: {
bodyParser: false
}
}
export async function POST(req) {
await connectMongo()
const { search } = await req.json()
if (!search)
return NextResponse.json({
hata: "Arama düzgünce işlenemedi."
})
const Books = await Book.findOne({ title: search })
console.log(`Her ÅŸey yolunda. ${search}`)
return NextResponse.json({
title: Books?.title,
description: Books?.description,
author: Books?.author,
id: Books?.id,
})
}My Model:
import { Schema, model } from "mongoose"
const BookSchema = new Schema({
title: String,
author: String,
id: Number,
description: String,
tag: {
name: String,
synonyms: [String]
}
}, {
collection: "kitaplar"
})
export default model("Book", BookSchema) || model.BookI tried old Next.js solutions but none of them worked. Please help
Via Active questions tagged javascript - Stack Overflow https://ift.tt/TqGlSmP
Comments
Post a Comment