我在Ionic 2和Angular2上开发了一个应用程序,MongoDB作为数据库,Node.js和Express.js作为服务器。我在笔记本电脑上创建了数据库mongoose.connect('mongodb://localhost:27017/db')
。
现在,我已经启动了AWS EC2 Linux实例并安装了node和npm软件包。
使用git repo在EC2 Linux实例中成功克隆了我的应用程序并安装了mongodb服务器,并通过在bindip
文件中发表mongod.conf
评论来连接到笔记本电脑的mongoDB的shell。
现在,当我在EC2实例中运行node server.js
时,会读取 server.js 文件中位于console.log(App listining to port 8080')
下方的app.listen(8080)
。之后没有任何事情发生。
mongoose.connect('mongodb://localhost:27017/db')
?作为参考,我附上 server.js 文件
server.js
var express = require("express");
var app = express();
var mongoose = require('mongoose');
var morgan = require('morgan');
var bodyParser = require('body-parser');
var cors = require('cors');
var methodOverride = require('method-override');
mongoose.connect('mongodb://localhost/reviewking');
app.use(morgan('dev')); // log every request to the console
app.use(bodyParser.urlencoded({ 'extended': 'true' })); // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
app.use(methodOverride());
app.use(cors());
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-control-Allow-Method", "DELETE,PUT");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
//Models
var Review = mongoose.model('Review', {
title: String,
description: String,
rating: Number
});
//Routes
app.get('/api/reviews', function (req, res) {
console.log('fetching reviews..');
Review.find(function (err, reviews) {
if (err)
res.send(err);
res.json(reviews);
});
});
app.post('/api/reviews',function(req,res){
console.log('creating reviews');
//create a review
Review.create({
title: req.body.title,
description:req.body.description,
rating:req.body.rating,
done:false
}, function(err, reviews){
if(err)
res.send(err);
Review.find(function(err,reviews){
if(err)
res.send(err);
res.json(reviews);
});
});
});
app.listen(8080);
console.log('app listening on port 8080')
答案 0 :(得分:0)
最简单的方法可能是运行mongodump
,将转储上传到您的服务器(可能使用scp)并使用mongorestore
进行恢复。
# Backup the reviewking database (on your laptop)
mongodump --db reviewking
# Restore the reviewking database (on your server)
mongorestore --db reviewking dump/reviewking