Mongoose查询返回空数组作为响应

时间:2017-02-10 12:06:57

标签: mongodb mean-stack mean

这是Morning Star架构:

var mongoose = require('mongoose');
    var Schema = mongoose.Schema;

var morningStarSchema = new Schema({
    title : {type: String, lowercase : true, required  :true},
    visit :  {type: String, lowercase : true, required  :true},
    Sightseeing : {type: String, lowercase : true, required  :true},
    image : {type: String},
    price : {type: String},
})


module.exports = mongoose.model('morningStar',morningStarSchema)
  1. 晨星架构的API
  2. 在MongoDB中使用集合创建数据库可以让游轮和雪假期中包含数据,但是当我得到请求时,我得到一个空数组

    var morningStar = require('../models/morningstar')
    
    module.exports = function (router) {
    
    router.post('/lets-cruise', function(req, res) {
        var user = new morningStar();
    
        user.title = req.body.title;
        user.visit    = req.body.visit;
        user.Sightseeing = req.body.Sightseeing;
        user.image = req.body.image;
        user.price = req.body.price
    
        user.save();
        res.send('User created')
    });
    
    router.get('/snow-vacations', function(req, res){
    
    morningStar.find(function(err, company) {
        if (err)
            {
            res.send(err);
    
            } else {
                res.json(company);
            }// return all nerds in JSON format
       });
    });
    
    return router;
    
    }
    

0 个答案:

没有答案