-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
84 lines (63 loc) · 1.98 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Mongoose database models and schemas
var config = require('./config/config'),
mongoose = require('mongoose'),
Schema = mongoose.Schema,
connection = mongoose.connection;
mongoose.connect(config.db.URI);
// Set up schemas
var interestSchema = new Schema({
name: String,
// Twitter handles associated with a given interest
twitter_names: [String],
needToRun: Boolean,
// Get the locations by calling:
// db.interest.findOne().populate('map_data.location').exec(
// function(err, result) {});
updated: {type: Date, default: Date.now}
});
var locationSchema = new Schema({
raw: String,
city: String,
state: String,
country: String,
state_short: String,
country_short: String,
});
var userSchema = new Schema({
twitter_id: Number,
location: {type: Schema.Types.ObjectId, ref: 'location'},
interests: [{type: Schema.Types.ObjectId, ref: 'interest'}]
});
var relativeSchema = new Schema({
percentage: String, //the other option is integer which isn't enough precision
type: String,
location: String
});
var interestLocationsSchema = new Schema({
interest: {type: Schema.Types.ObjectId, ref: 'interest'},
type: String,
location: String,
location_short: String,
location_parent: String,
count: {type: Number, default: 1 }
});
var statSchema = new Schema({
retrieved_followers: Number,
cached_users: Number,
new_uncached_users: Number,
before_remove_prev_counted: Number,
after_remove_prev_counted: Number,
time_to_run: Number,
interest: {type: Schema.Types.ObjectId, ref: 'interest'},
error_message: String,
error_function: String
});
// Export models
module.exports = {
relativePopulation: mongoose.model('relativeSchema', relativeSchema),
interest: mongoose.model('interest', interestSchema),
location: mongoose.model('location', locationSchema),
interest_locations: mongoose.model('interest_locations', interestLocationsSchema),
user: mongoose.model('user', userSchema),
stat: mongoose.model('stat', statSchema)
};