nodejs查询


const tagModel = require("../mongodb");

 1 const mongoose = require("mongoose");
 2 mongoose.connect("mongodb://127.0.0.1:27017/Test")
 3 const tagSchema = new mongoose.Schema({
 4     text: {
 5         type: String,
 6         minlength: 2,
 7         maxlength: 12
 8     }
 9 })
10 const tagModel = new mongoose.model("tag", tagSchema);
11 
12 module.exports = tagModel;

 


1
module.exports = function (router) { 2 router.get("/tag", async (ctx) => { 3 // const arr = [{ text: "HTML" }, { text: "SQL" }, { text: "nodejs" },] 4 // tagModel.insertMany(arr, function (err, docs) { 5 // console.log(err); 6 // console.log(docs); 7 // }); 8 9 //查询 10 const data = await tagModel.find({}); 11 12 ctx.body = { 13 status: 200, 14 data: data, 15 msg: "" 16 } 17 }) 18 }

 

posted @ 2021-11-29 19:22  小小不小阿  阅读(113)  评论(0编辑  收藏  举报