Created
June 2, 2012 19:19
-
-
Save sadasant/2859635 to your computer and use it in GitHub Desktop.
Connecting to mongolabs example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Dependencies. | |
*/ | |
var MongoStore = require('connect-mongo') | |
, mongoose = require('mongoose') | |
, express = require('express') | |
, app = module.exports = express.createServer() | |
/** | |
* Connecting. | |
*/ | |
var _s = require('./secret') | |
mongoose.connect('mongodb:'+_s.mongoUrl) | |
// Models | |
var App = {} | |
App.models = { | |
users: new mongoose.Schema({ | |
_id : mongoose.Schema.ObjectId | |
, user : String | |
, email : String | |
, password : String | |
}) | |
} | |
App.User = mongoose.model('users', App.models.users) | |
//var test = new App.User({ user: 'test', password: 'test' }) | |
//test.save(function(err){ console.log(err) }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//secret.js | |
/** | |
* Secret variables and values. | |
* | |
* You have to fill this data with our mongolab account. | |
*/ | |
exports.db = db | |
var db = { | |
db : "database_name" | |
, host : "???.mongolab.com" | |
, port : "?????" | |
, username : "?????????" | |
, password : "?????????" | |
, collection : 'collection_name' | |
} | |
exports.mongoUrl = db.username+":"+db.password+"@"+db.host+":"+db.port+"/"+db.db; | |
exports.session = "??????????????"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment