生于理想

导航

随笔分类 -  Node

模板配置-模板根目录及后缀配置
摘要:const template = require('art-template'); const path = require('path'); // 时间 const sd = require('silly-datetime'); //设置模板根目录 template.defaults.root = 阅读全文

posted @ 2022-09-23 17:17 生于理想 阅读(28) 评论(0) 推荐(0)

记录nodejs中querystring‘已弃用’三种处理方法
摘要:一.升级node版本,修改引入方式 //升级到18.x版本后修改引入方式 const querystring= require('node:querystring') 二.官方推荐URLSearchParams替代 因为不想升级就按照文档先用了URLSearchParams const url = 阅读全文

posted @ 2022-09-21 16:48 生于理想 阅读(749) 评论(0) 推荐(1)

集合关联
摘要:多集合联合查询(集合关联) 通常不同集合的数据之间是有关系的,例如文章信息和用户信息存储在不同集合中,但文章是某个用户发表的,要查询文章的所有信息包括发表用户,就需要用到集合关联。 const mongoose = require('mongoose'); mongoose.connect('mon 阅读全文

posted @ 2022-09-20 20:06 生于理想 阅读(45) 评论(0) 推荐(0)

MongoDB-mongoose验证
摘要:Mongoose验证 在创建集合规则时,可以设置当前字段的验证规则,验证失败就则输入插入失败。 常见的验证规则: - required: true 必传字段 - minlength:3 字符串最小长度 - maxlength: 20 字符串最大长度 - min: 2 数值最小为2 - max: 10 阅读全文

posted @ 2022-09-20 18:28 生于理想 阅读(54) 评论(0) 推荐(0)

MongoDB增删改查
摘要:向数据库中导入数据 mongoimport -d 数据库名称 -c 集合名称 --file 要导入的文件 mongoimport -d playground -c users --file ./user.json 查询 // 查询用户集合中的所有文档 // User.find().then(resu 阅读全文

posted @ 2022-09-20 18:20 生于理想 阅读(32) 评论(0) 推荐(0)

MongoDB连接数据库-创建集合以及向集合中插入文档(方法*2)
摘要:方法1 // 引入mongoose第三方模块 用来操作数据库 const mongoose = require('mongoose'); // 数据库连接 mongoose.connect('mongodb://localhost/playground', { useNewUrlParser: tr 阅读全文

posted @ 2022-09-20 16:57 生于理想 阅读(54) 评论(0) 推荐(0)

joi验证报错UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
摘要:(node:2072) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client at new NodeError (in 阅读全文

posted @ 2021-11-29 19:07 生于理想 阅读(583) 评论(0) 推荐(0)