-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.ts
32 lines (28 loc) · 1.08 KB
/
schema.ts
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
import { Bike, Route, Trip } from "./typings";
import { Schema } from "mongoose";
import "mongoose-geojson-schema";
export const BikeSchema = new Schema<Bike>({
bikeId: { type: String, required: true, unique: true },
station: { type: Number, required: true },
timestamp: { type: Number, required: true },
});
export const TripSchema = new Schema<Trip>({
id: { type: String, required: true, unique: true },
bikeId: { type: String, required: true, index: true },
route: { type: String, required: true, index: true },
start: { type: Number, required: true },
end: { type: Number, required: true },
});
export const RouteSchema = new Schema<Route>({
id: { type: String, required: true, unique: true },
start: { type: Number, required: true },
end: { type: Number, required: true },
path: {
type: Schema.Types.LineString,
required: true,
},
distance: { type: Number, required: true },
duration: { type: Number, required: true },
});
RouteSchema.index({ path: "2dsphere" });
RouteSchema.index({ start: 1, end: 1 }, { unique: true });