Mongoose Schema Sample
JS
S
JavaScriptSimple Mongoose Schema Sample using commonly used DataTypes and with 2 Foreign Collection references one automatic and another one for enabling Mongoose limited sub-document population using manual references.
1const TelemetrySchema = new Schema({
2 plan: {
3 type: Schema.Types.ObjectId,
4 ref: 'plan'
5 },
6 period: {
7 type: String,
8 default: 'month'
9 },
10 refreshDate: {
11 type: Date,
12 required: true
13 },
14 cancelled: {
15 type: Boolean,
16 default: false
17 },
18 token: {
19 type: String,
20 default: uuid()
21 },
22 stationId: {
23 type: Schema.Types.ObjectId,
24 index: true
25 },
26 expirationDate: Date,
27 additionalServices: [
28 {
29 description: {
30 type: String
31 },
32 counter: {
33 type: Number
34 },
35 _id : false
36 }
37 ]
38});Created on 5/8/2018