![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
mongoDB
柠檬不萌只是酸i
研究生在读 | 努力发论文 |
迈出第一步,才是新的开始。
展开
-
DeprecationWarning: Mongoose: `findOneAndUpdate()` and `findOneAndDelete()` without the `useFindAndM
DeprecationWarning: Mongoose: `findOneAndUpdate()` and `findOneAndDelete()` without the `useFindAndModify` option set to false are deprecated. See: https://mongoosejs.com/docs/deprecations.html#-finda...原创 2020-01-01 17:11:55 · 3058 阅读 · 0 评论 -
mongodb中的正则,使用正则进行模糊匹配
MongoDB使用$regex 操作符来设置匹配字符串的正则表达式。????栗子:查询姓名里面含有 ’张‘ 的.db.getCollection('elementusers').find({ username:{ $regex:'张' }})例子提供的数据:{ "_id":ObjectId("5de772b27f62065b6c1cab4...原创 2019-12-04 17:21:15 · 1263 阅读 · 0 评论 -
mongoose 完成分页数据查询
分页后端代码如下:/** * 获取用户列表信息 [需要分页的] * @params pageNum 第几页的数据 [必传] * @params pageSize 一页显示几条数据 [必传] */router.post('/getUsersList.do', async (req, res) => { const pageNum = Numbe...原创 2019-12-04 17:02:55 · 830 阅读 · 0 评论 -
mongoose中报错 MongoError: E11000 duplicate key error collection、 code: 11000
问题描述:MongoError: E11000 duplicate key error collection: test.elementusers index: username_1 dup key: { username: "admin" } at Function.create (/Users/liangrumeng/Documents/HBuilderProjects/wor...原创 2019-12-04 14:42:17 · 2779 阅读 · 0 评论 -
如何将本地的mongodb数据导出,然后上传至阿里云服务器上mongodb中呢?
(1)使用MongoDB Compass 可视化工具将本地数据库导出。【Collection ----> Export Collection 】(2)将本地导出的mongodb数据库表上传至服务器上的任意位置:【我使用的是Yummy FTP Pro】【我上传到服务器的位置:/usr/local/server/mongodb_file】(3)在服务器上使用命令,将/...原创 2019-11-25 14:20:16 · 1231 阅读 · 2 评论 -
express中使用的加密工具、使用bcrypt来对用户的密码进行加密。bcrypt 一个跨平台的文件加密工具。
bcrypt,是一个跨平台的文件加密工具。由它加密的文件可在所有支持的操作系统和处理器上进行转移。它的口令必须是8至56个字符,并将在内部被转化为448位的密钥。(1)安装bcryptnpm install bcrypt --save(2)使用加密:哈希密码,有两种方式:(2-1)在单独的函数调用上生成salt和hash。varsalt=bcrypt.genSalt...原创 2019-11-09 10:09:12 · 845 阅读 · 0 评论 -
解决mongoose中的Schema设置unique不生效问题?
unique属于Schema约束验证中的一员,它的作用主要就是让某一个字段的值具有唯一性(不能重复)例如:用户名不能重复,我们可以这样设置(如下) // 创建Schema对象var loginSchema = new Schema({ username:{ type:String, unique:true }, password:...原创 2019-11-08 18:38:04 · 3125 阅读 · 1 评论 -
【附后端代码】使用 express + mongoose 实现添加产品和获取产品列表(分页查询)
【创建Schema模型】:/** * product模型对象 */var mongoose = require('mongoose');var Schema = mongoose.Schema; // 创建Schema对象var productSchema = new Schema({ name:{ // 产品名称 string type:Stri...原创 2019-11-08 16:56:36 · 505 阅读 · 0 评论 -
【mongoose报错】DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
问题描述:mongoose在Schema中添加unique:true 属性的时候,控制台出现这样的警告:⚠️(node:41955) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.解决办法:在连接数据库的上面添加如下:mongoose.set('useCr...原创 2019-11-08 16:43:39 · 590 阅读 · 0 评论 -
【mongoose】中的踩坑 Cannot overwrite `category` model once compiled.
Cannot overwrite `category` model once compiled.翻译:编译后无法覆盖“category”模型。很纳闷,定义了个Schema,然后在定义Model,再到document,于是按照顺序检查了下代码:var mongoose = require('mongoose');var Schema = mongoose.Schema;// 创建S...原创 2019-11-08 15:41:53 · 2287 阅读 · 2 评论 -
option { useNewUrlParserpass:tr} option { useUnifiedTopology: true } to the MongoClient constructor.
问题描述:the options [usenewurlparser] is not supported(node:12148) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass opt...原创 2019-10-22 11:17:59 · 6772 阅读 · 5 评论 -
使用mongoose , 完成增删改查
(1)查询数据//1. 引入mongoose const mongoose = require('mongoose');//2. 建立连接mongoose.connect('mongodb://127.0.0.1:27017/test',{useNewUrlParser:true});//3. 操作users表(集合) 定义一个Schema,可以对字段的名字进行判断。 Sche...原创 2019-07-26 18:01:35 · 194 阅读 · 0 评论 -
【mongoose 】:DeprecationWarning: current URL string parser is deprecated, and will be removed in
DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.mongoose连接...原创 2019-07-25 16:08:22 · 616 阅读 · 0 评论