-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathurls-db.js
28 lines (24 loc) · 844 Bytes
/
urls-db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var Mongolian = require('mongolian');
// Make BSON play nicely with us.
var ObjectId = Mongolian.ObjectId;
ObjectId.prototype.toJSON = ObjectId.prototype.toString;
if (process.env.MONGO_SITES){
db = new Mongolian(process.env.MONGO_SITES);
} else {
var server = new Mongolian;
// Mongo doesn't return the db proper when connected without
// authentication (as in local).
db = server.db('pantheon-app');
}
exports.list = function(isGod, callback){
var collection = (isGod) ? 'godsites' : 'demisites';
var sites = db.collection(collection);
sites.find().limit(10).sort({time: -1}).toArray(function(err, array){
callback(array);
});
};
exports.add = function(isGod, data){
var collection = (isGod) ? 'godsites' : 'demisites';
var sites = db.collection(collection);
sites.insert(data);
};