时间:2021-07-01 10:21:17 帮助过:21人阅读
2.router中
var router = require(‘koa-router‘)(); var mongoose = require(‘mongoose‘); mongoose.Promise = global.Promise; //初始化 //mongoose.Promise = require(‘bluebird‘); //疑似高效 //----------------希望建个module文件放在里面 var db = mongoose.connect(‘mongodb://localhost/mydb‘); var User = mongoose.model(‘user‘, new mongoose.Schema({ email: String, pwd: String, nicheng: String, },{_id:true})); //====================================== router.post(‘/zhuce‘, function *(next) { let subflag = this.query[‘subflag‘]; let email = this.request.body[‘email‘]; //this.body = ‘收到email:‘+email+‘,get收到:‘+subflag; var user = new User({uname:‘dd‘,pwd:‘dd‘}); user.nicheng=‘张三‘; user.age=20; //无效 yield user.save(); this.body = user._id; })
koa1链接mongodb
标签:route host glob new UI 高效 pwd query cal