Skip to content

Commit a2e8fe2

Browse files
committed
move settings of db to config
1 parent 7ccaca9 commit a2e8fe2

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed

config.example.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
exports.database = {
2-
name: 'recipedb',
3-
collection: 'recipes'
2+
local_db_uri: 'mongodb://localhost/xxxx',
3+
collection: 'xxxx'
44
}

config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
exports.database = {
2-
name: 'recipedb',
2+
local_db_uri: 'mongodb://localhost/recipedb',
33
collection: 'recipes'
44
}

models/database.js

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
1-
var config = require('../config')
2-
, mongojs = require('mongojs');
1+
var config = require('../config'),
2+
mongojs = require('mongojs'),
3+
mongo = require('mongodb'),
4+
settings = config.database,
5+
mongoUri = process.env.MONGOLAB_URI || process.env.MONGOHQ_URL || settings.local_db_uri;
36

4-
settings = config.database;
5-
6-
function Database () {
7-
//var db = mongojs(process.env.MONGOLAB_URI || process.env.MONGOHQ_URL || settings.name, ['recipes']);
8-
//this.db = db;
9-
//this.collection = settings.collection;
10-
}
7+
function Database () {};
118

129
Database.prototype = {
1310
getSearchResults: function (res, data, callback) {
1411

15-
var mongo = require('mongodb');
16-
17-
var mongoUri = process.env.MONGOLAB_URI || process.env.MONGOHQ_URL || 'mongodb://localhost/mydb';
18-
1912
var re = new RegExp(data.searchTerm, "i");
2013
mongo.Db.connect(mongoUri, function (err, db) {
21-
db.collection('recipes', function(er, collection) {
14+
db.collection(settings.collection, function(er, collection) {
2215
collection.find({'name': re}).toArray(function(err, items) {
23-
console.log(items);
24-
2516
if(er) {
2617
callback(true, data);
2718
return;
@@ -32,6 +23,6 @@ Database.prototype = {
3223
});
3324
});
3425
}
35-
}
26+
};
3627

3728
exports.Database = Database;

0 commit comments

Comments
 (0)