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
发布评论