我无法连接到mongo,我尝试了所有链接。请任何人帮助我花了这么多时间在这个问题上,我无法弄清楚任何解决方案。 为任何想要
的人安装mongodbvar 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);