无法使用 mongodb 在 Nodejs 中运行 API

编程入门 行业动态 更新时间:2024-10-10 04:24:41

无法使用 <a href=https://www.elefans.com/category/jswz/34/1771382.html style=mongodb 在 Nodejs 中运行 API"/>

无法使用 mongodb 在 Nodejs 中运行 API

我正在使用 nodejs(expressjs),现在我正在尝试使用“API”,但出现以下错误

{"success":false,"error":{"ok":0,"code":8000,"codeName":"AtlasError"}}

这是我的“控制器文件”(plan-ctrl.js)

export const getPlans = async (req, res) => {
    await Plan.find({}, (err, plans) => {
        if (err) {
            return res.status(400).json({ success: false, error: err })
        }
        if (!plans.length) {
            return res
                .status(404)
                .json({ success: false, error: `Plans not found` })
        }
        return res.status(200).json({ success: true, data: plans })
    }).clone().catch(err => console.log(err))
}

这是我的“模型”(plan-model.js)

import mongoose from 'mongoose';
const Schema = mongoose.Schema

const Plan = new Schema(
    {
        name:  { type: String, required: true },
        price:  { type: Number, required: true },
        branches:  { type: Number, required: true },
        flows:  { type: Number, required: true },
        assignees:  { type: Number, required: true },
        gitignore:  { type: Boolean, required: true },
        priority:  { type: Boolean, required: true },
        multistore:  { type: Boolean, required: true },
    }
)
export default mongoose.model('plans', Plan)
Here is my data in database(mongodb/mongoose) in "claudmongo" ( connection established successfully)
_id : ObjectId(6390bfacbe1XXXXXXXXXXXX)
name:"Free"
price:"0"
branches:"2"
flows:2
assignees:null
gitignore:null
priority:null
multistore:false
color:"#969696"
...
回答如下:

更多推荐

无法使用 mongodb 在 Nodejs 中运行 API

本文发布于:2024-05-13 15:00:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1759768.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:mongodb   Nodejs   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!