# mongodb **Repository Path**: topazur/mongodb ## Basic Information - **Project Name**: mongodb - **Description**: hybrid项目接口 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-05-09 - **Last Updated**: 2020-12-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 所有项目的接口都在这里 写/开发 express 基于 Node.js 平台,快速、开放、极简的 web 开发框架。 (nodeJs+mongoDB+express+bootStrap) 后台管理系统 # 每个模块的作用:↓↓↓在这里需要与否 ### http -- 起服务 ### path -- Node 自带模块 - 拆分目录 ### qs-- Node 自带模块 ### crypto -- crypto模块功能是加密并生成各种散列 ## 需要安装的↓↓↓ ### express -- 你说要不要??? ### mongoose -- 连接数据库(比mongodb好用) ### ejs -- js解析html ## 前后端分离不需要的插件 - 都在前端处理了 ### debug -- onListening(listening回调) ### cookie-parser -- 处理服务器Cookie ### express-session -- 处理session ### morgan -- 处理日志 ### multiparty -- 解析上传文件 ### formidable -- 解析上传文件 ### supervisor -- 监听文件修改,类似于nodemon的watch > "start": "node ./bin/www", > "watch": "nodemon app.js", > "dev": "supervisor ./bin/www" ### jsonwebtoken ### node-uuid -- 生成全球唯一id ### cnpm i apidoc -g -- 生成接口文档(注释的形式编写,生成对应的ejs模板) > apidoc -i routes/ -o public/doc [大勋说](https://blog.csdn.net/daxunshuo) express -e "名字" (生成ejs 模板引擎 的工程) 是文件夹my-exp 和express1706 --frame-express这种包含.ejs解析页面的后台系统页面 而现在写vue等框架项目: 只需要部分express功能(比如不需要views等包含.ejs页面的东西),它的作用只是又来写接口!!! 原来的express的起服务写在www里面,app是写中间件的。而在这里不需要中间件 启动服务:npm start;npm run watch。在package.json中的script定义,只有start能够省略。 utils里面的connect.js导入app.js; schema.js导入路由。 get - req.query; post - req.body。 ## 只写接口则不能直接建一个工程 1. app.js - 启动项目 ## 连接DB ```js // 导入Model 构造器 // let { Movie } = require("./schema"); // // 先实例化为文档,再使用save()方法保存文档 save // 集合名称为"模型名称的小写复数版"-为了避免可在末尾加数字 // 通过new Model1()创建的文档doc1,必须通过save()方法,才能将创建的文档保存到数据库的集合中 // 第一次:若没这个集合的时候,添加内容;使表存在 // new Movie({ name: "肖申克的救赎" }).save((err, doc) => { // console.log(doc); // }) // 就是空表是不存在的,只有表里面有数据时才能存在,不然只是白创建 function zhushi() { /* 创建文档(表)之后, 进行增删改查******************************** // 删除 deleteOne deleteMany remove // Movie.deleteMany({ // // nation: "美国" // // username: /huajianhua/ // // name: "肖申克的救赎1", // "_id" : "5dd7e34ac23c124c1c2e4747" // }).then(result => { // console.log(result) // }) 修改 update() updateMany() find() + save() updateOne() findOne() + save() findByIdAndUpdate() fingOneAndUpdate() // Movie.update({ // name: "肖申克的救赎1" // }, { // $set: { // name: "肖申克的救赎", // } // }).then(result => { // console.log(result); // }) // Movie.updateMany({ // name: "肖申克的救赎" // }, { // $set: { // name: "肖申克的救赎1", // nation: "美国" // } // }).then(result => { // console.log(result); // }) // 增加 // User.create({ // username:"coco88" // },{ // username:"mumu88" // }).then(result=>{ // console.log(result); // }); // User.insertMany([{username:"武汉1909"},{username:'are youok '}]).then(result=>{ // console.log(result); // }) // fs.readFile('./cinemas.json', 'utf8', (err, data) => { // console.log(err); // if (err) throw err; // console.log(data); // 为什么变量不行 // Movie.insertMany(data).then(result => { // console.log(result); // }) // }); // Movie.insertMany([ // 插入的内容 // ]).then(result => { // console.log(result); // }) // 查找 // 排序 sort // Movie.find({}, {}).sort({ _id: -1 }).then(result => { // console.log(result); // }) // Movie.find({}, {}).sort({ _id: -1 }).then(result => { // // console.log(result); // // const http = require("http"); // function initServer(url, data) { // http.createServer((req, res) => { // if (req.url == url) { // res.writeHead(200, { "content-type": 'application/json' });//接收 josn 格式数据 // res.write(JSON.stringify(data)); // res.end(); // } // }).listen(3000, "0.0.0.0", () => { // console.log("spider server is running at http://localhost:3000") // }) // } // initServer('/movie', result); // }) */ } ```