随笔分类 -  MongoDb

摘要:1,连接数据库: cmd 进入终端,输入 mongo 输入 show dbs 可以看到所以的数据库: 刚开始会有这三个数据库 2,创建数据库(加入创建一个 hello 的数据库) 需要 往 hello 数据库的 user 集合中插入一条数据,数据库才真正创建成功 3,插入(增加)数据 db.user 阅读全文
posted @ 2021-02-02 00:28 shanlu 阅读(155) 评论(0) 推荐(0)
摘要:1,explain explain 会帮助你获得查询方面诸多有用的信息。只要对游标调用该方法,就可以得到查询细节。explain 会返回一个文档,而不是游标本身 > use hello switched to db hello > db.user.find().explain("executionS 阅读全文
posted @ 2021-02-02 00:26 shanlu 阅读(62) 评论(0) 推荐(0)
摘要:1,创建超级管理用户: > show dbs admin 0.000GB config 0.000GB local 0.000GB > use admin switched to db admin > db.createUser({ ... user:"admin", ... pwd:"123", 阅读全文
posted @ 2021-02-02 00:25 shanlu 阅读(77) 评论(0) 推荐(0)
摘要:使用聚合管道可以对集合中的文档进行变换和组合 用于表关联查询、数据的统计等。 MongoDB 使用 db.COLLECTION_NAME.aggregate([{<stage>} , ... ]) 方法来构建和使用聚合管道。 MongoDB Aaggregation 管道操作符与表达式: ① $pr 阅读全文
posted @ 2021-02-01 23:23 shanlu 阅读(581) 评论(0) 推荐(0)
摘要:安装 MongoDB npm install mongodb --save 连接 MongoDB 数据库: //引入mongodb const {MongoClient} = require('mongodb') //定义数据库连接的地址 //const dataUrl = 'mongodb://1 阅读全文
posted @ 2021-02-01 23:20 shanlu 阅读(187) 评论(0) 推荐(0)
摘要:const http = require('http'); const Router = require('./Router') const {MongoClient} = require('mongodb') const ejs = require('ejs') const queryString 阅读全文
posted @ 2021-02-01 23:18 shanlu 阅读(397) 评论(0) 推荐(0)
摘要:解决原生NodeJS 操作MongoDB 数据库的性能问题,封装成更小、更灵活的操作MongoDB库: Config.js 将所要连接的数据的配置信息封装成一个模块: const Config = { dbUrl:'mongodb://admin:123@localhost:27017/', dbN 阅读全文
posted @ 2021-01-30 18:58 shanlu 阅读(241) 评论(0) 推荐(0)
摘要:添加用户:跳转到添加页面(一个添加的表单) 编辑用户:跳转到编辑页面(跳转过去要携带所编辑用户的id,查询到所编辑的该用户信息,获取编辑后传过来的值修改数据库中的数据) 删除用户:获取所要删除的用户的 id,执行数据库的删除操作 添加页面: 编辑页面: 路由配置: 首页,需要查询数据库中的用户信息并 阅读全文
posted @ 2021-01-30 18:54 shanlu 阅读(98) 评论(0) 推荐(0)