首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Document()的参数\"obj\“必须是对象

Document()的参数\"obj\“必须是对象
EN

Stack Overflow用户
提问于 2021-06-07 19:14:32
回答 2查看 178关注 0票数 0

我正在创建一个具有next.js应用编程接口功能的全栈项目。以下是以下组件。当我向api发出post请求时,会出现以下错误。我已经看过了堆栈溢出上的所有类似链接

错误Parameter \"obj\" to Document() must be an object, got {\r\n \"name\": \"Charming Studio < 10 Miles to Wells' Beaches!\",\r\n \"pricePerNight\": 168,\r\n \"description\": \"A friendly atmosphere and natural delights await your visit to the town of Wells! Stay at this well-equipped 1-bath studio and enjoy easy access to several beaches, including Wells Beach and Drakes Island Beach, as well as Rachel Carson National Wildlife Refuge - the best spot for wildlife viewing just 8 miles away. Not to mention, with the downtown area just 10 mi

index.js

代码语言:javascript
复制
import nc from "next-connect";
import { allRooms, newRoom } from "../../../controllers/roomControllers";
const handler =nc();
if (mongoose.connection.readyState >= 1) {
    return;
  }
  mongoose.connect(process.env.DB_LOCAL_URI, {
    useCreateIndex: true,
    useFindAndModify: false,
    useUnifiedTopology: true,
    useNewUrlParser: true,
  }).then(connect=>console.log("connected to local data base "))

handler.post(newRoom);

新房间

代码语言:javascript
复制
import Room from "../models/Rooms";
export const newRoom = async (req, res) => {
  try {
    const room =await Room.create(req.body);
    res.status(200).json({
      room,
    });
  } catch (err) {
    res.status(400).json({
      error: err.message
    });
  }};

房间模型

代码语言:javascript
复制
import mongoose from 'mongoose'
const roomSchema = new mongoose.Schema({
   // all schema values 
})

module.exports = mongoose.models.Room || mongoose.model('Room', roomSchema);
EN

回答 2

Stack Overflow用户

发布于 2021-07-17 01:19:44

我认为您可以尝试使用JSON格式插入原始表单正文,而不是在Postman中插入文本。

票数 0
EN

Stack Overflow用户

发布于 2021-11-03 01:47:49

此错误源于您在代码中传递的不存在的内容。您应该查找此参数并将其从代码中移除或为其添加值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67870581

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档