2015-05-21 4 views
0

Я разработал простое приложение CRUD для стека приложений. Я развернул свой сайт на лазурных сайтах. В моем локальном приложении приложение работает нормально. Но я хочу подключиться к базе данных mongoLab. Как я могу подключить его?Как подключиться к mongoLab?

Это код server.js

var express = require('express'); 
var app = express(); 
var mongojs = require('mongojs'); 


var db = mongojs('posts', ['posts']); 
var bobyParser = require('body-parser'); 

app.use(express.static(__dirname + "/public")); 
app.use(bobyParser.json());// 
app.get('/posts', function (req, res) { 
console.log("I got the server request!") 
db.posts.find(function (err, docs) { 
    console.log(docs); 
    res.json(docs); 
}); 
}); 



app.post('/posts', function (req, res) { 
console.log(req.body); 
//Insert - This is the first part of the CRUD 
db.posts.insert(req.body, function (err, doc) { 
    res.json(doc); 
}); 
}); 


app.delete('/posts/:id', function (req, res) { 
var id = req.params.id; 
console.log(id); 
db.posts.remove({ _id: mongojs.ObjectId(id) }, function (err, doc) { 
    res.json(doc); 
}); 
}); 


app.get('/posts/:id', function (req, res) { 
var id = req.params.id; 
console.log(id); 
db.posts.findOne({ _id: mongojs.ObjectId(id) }, function (err, doc) { 
    res.json(doc); 
}); 
}); 

app.put('/posts/:id', function (req, res) { 
var id = req.params.id; 
console.log(req.body.name); 
db.posts.findAndModify({ 
    query: { _id: mongojs.ObjectId(id) }, 
    update: { $set: { name: req.body.name, info: req.body.info, twitter:   req.body.twitter }}, 
    new: true 
}, function (err, doc) { 
    res.json(doc); 
}); 
}); 

app.listen(3000); 
console.log("Server running from port 3000"); 

Как я могу сделать соединение? У меня есть информация о подключении, которую предоставляет azure. Большое спасибо.

ответ

0

Вы можете посмотреть точное сообщение об ошибке Exception? Попробуйте что-то вроде следующего:

 try 
     { 
      smtp.Send(msg); 
      Response.Write("<script>alert('Mensaje enviado correctamente');</script>"); 
      NullTextBox(); 
     } 
     catch (Exception ex) 
     { 
      Response.Write(string.Format("<script>alert('There is an error on connection to DB on microsoft azure:{0}');</script>", ex.ToString())); 
      NullTextBox(); 
     } 

enter image description here

Смежные вопросы