无法连接到mongoose,MongoError:首次连接

时间:2017-02-24 09:34:56

标签: mongodb mongoose

我无法连接到mongo,我尝试了所有链接。请任何人帮助我花了这么多时间在这个问题上,我无法弄清楚任何解决方案。 为任何想要

的人安装mongodb
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mongoose = require('mongoose');

mongoose.connect('mongodb://localhost/blogfall2016');

var PostSchema= mongoose.Schema({
title: {type: String, required: true},
body: String,
tag: {type:String, enum:['POLITICS','ECONOMY','EDUCATION']},
posted: {type:Date, default:Date.now()}

});

var PostModel =mongoose.model("PostModel",PostSchema);


app.use(express.static(__dirname + '/public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.post("/api/blogpost", createPost);

function createPost(req, res) {
var post = req.body;
console.log(post);
res.json(post);

}

app.listen(3000);

0 个答案:

没有答案