search

Home  >  Q&A  >  body text

mongoose query error - Stack Overflow

This code reports an errorvar queryAll = user_model.find();, I don’t know where the error is in this code, please help someone with experience,

// login action

const  express = require('express');
var mongoose = require('mongoose');

var User_Model = mongoose.model('User_Model');

const router = express.Router();

router.get('/',(req,res,next)=>{
    res.render('login.html');
});

module.exports=router;



router.post('/',(req,resp,next)=>{

    debugger;
    //连接数据库
    mongoose.connect('mongodb://127.0.0.1:27017/likeread',(err)=>{
        if(err)
            console.log('err');
    });

    console.log(mongoose);

    var user_model = new User_Model();

    debugger;
    //查找数据
    var queryAll = user_model.find({});

    queryAll.exec((err,result)=>{
        if(err){
            console.log(err);
        }else{
            console.log(result);
        }
    });


    debugger;
    user_model.close((err,res)=>{
        if(err){
            console.log(err);
        }
    });

    debugger;

    resp.end();
});
迷茫迷茫2733 days ago612

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-05-31 10:43:47

    var queryAll = User_Model.find({});

    reply
    0
  • Cancelreply