nodejs查询
2024-10-21 11:41:11
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 }
最新文章
- 领域驱动和MVVM应用于UWP开发的一些思考
- VS快速生成JSON数据格式对应的实体
- JavaScript UI选型及Jquery EasyUI使用经验谈
- js-JavaScript高级程序设计学习笔记17
- 对弈类游戏的人工智能(5)--2048游戏AI的解读
- Linux下各个目录的作用
- 一、HTML和CSS基础--HTML+CSS基础课程--第3部分
- Design Patterns---- Strategy 模式
- Window 2008 R2 + IIS7.5 + VS2013 错误代码 0x80070002
- HDOJ-1041 Computer Transformation(找规律+大数运算)
- Jquery学习笔记:获取jquery对象的基本方法
- 如何用C#使用java
- HDU - 1907 John 反Nimm博弈
- jquery实现ajax提交表单的方法总结
- Python中的鸡肋多线程
- elasticsearch 使用快照进行备份
- AndroidStudio 开发JNI
- browse-agent type and curl post
- C++中 explicit的用法
- java.lang.String cannot be cast to java.util.Date