1:在页面写修改
//引入mongodb.js const {userModel} = require("../mongodb"); //引入toast.js const { success, fail } = require("../toast"); //用户路由 //module.exports导出 module.exports=function(router){ //查询 router.get("/user", async (ctx) => { try {//成功 const data = await userModel.find(ctx.query);//查找全部 await 等待tagModel.find({})执行成功 return success(ctx, data); } catch (error) { //失败 return fail(ctx, error) } }) //添加post router.post("/user", async ctx => { try { const data = await userModel.create(ctx.request.body); return success(ctx, data); } catch (error) { return fail(ctx, error) } }) //删除 deleteOne只删除一条 router.delete("/user", async ctx => { try { const data = await userModel.deleteOne(ctx.request.body); return success(ctx, data); } catch (error) { return fail(ctx, error) } }) //修改 router.put("/user", async ctx => { try { const data = await userModel.updateOne(ctx.query,ctx.request.body); return success(ctx, data); } catch (error) { return fail(ctx, error) } }) }
2:在test.http页面写
###查询内容 get {{url}}/content ###添加内容 POST {{url}}/content {{json}} { "title":"titletitle", "content":"contentcontentcontentcontent" } ###修改内容 PUT {{url}}/content?_id=61a88229908b15dcf22b9586 {{json}} { "top": true } ### 删除 DELETE {{url}}/content {{json}} { "_id": "61a8872e2c1dabf00c737417" }