1. Installing MongoDB and Mongoose under the project
NPM Install MongoDB--save---save-dev
In 2.router
varRouter = require (' Koa-router '))();varMongoose = require (' Mongoose ')); Mongoose. Promise= Global. Promise;//Initialize//Mongoose. Promise = require (' Bluebird '); Suspected high efficiency//----------------want to put a module file in there .vardb = Mongoose.connect (' Mongodb://localhost/mydb ');varuser = Mongoose.model (' user ',NewMongoose. 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 = ' received email: ' +email+ ', Get Received: ' +subflag; varuser =NewUser ({uname: ' dd ', pwd: ' DD ')}); User.nicheng= ' Zhang San '; User.age= 20;//Invalidyield User.save (); This. BODY =user._id;})
KOA1 Link MongoDB