-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.js
34 lines (29 loc) · 1.04 KB
/
model.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
// Pulls Mongoose dependency for creating schemas
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
// Creates a User Schema. This will be the basis of how user data is stored in the db
var UserSchema = new Schema({
_id: Number,
querywindowId: Number,
rank: Number,
twitterid: Number,
tag: String, // [Long, Lat]
lat: Number,
lng: Number,
htmlverified: String,
created_at: {type: Date, default: Date.now},
updated_at: {type: Date, default: Date.now}
});
// Sets the created_at parameter equal to the current time
UserSchema.pre('save', function(next){
now = new Date();
this.updated_at = now;
if(!this.created_at) {
this.created_at = now
}
next();
});
// Indexes this schema in 2dsphere format (critical for running proximity searches)
UserSchema.index({location: '2dsphere'});
// Exports the UserSchema for use elsewhere. Sets the MongoDB collection to be used as: "scotch-users"
module.exports = mongoose.model('NewSchema', UserSchema);