forked from MyZubster-Ecosystem/myzubster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGarden.js
More file actions
64 lines (61 loc) 路 1.3 KB
/
Copy pathGarden.js
File metadata and controls
64 lines (61 loc) 路 1.3 KB
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
const mongoose = require('mongoose');
const gardenSchema = new mongoose.Schema(
{
name: {
type: String,
required: true,
trim: true,
maxlength: 120,
},
description: {
type: String,
trim: true,
default: '',
},
address: {
type: String,
required: true,
trim: true,
maxlength: 300,
},
neighborhood: {
type: String,
trim: true,
default: '',
},
city: {
type: String,
trim: true,
default: '',
},
coordinates: {
lat: { type: Number, required: true, min: -90, max: 90 },
lng: { type: Number, required: true, min: -180, max: 180 },
},
ownerId: {
type: String,
trim: true,
default: '',
},
isActive: {
type: Boolean,
default: true,
},
},
{
versionKey: false,
timestamps: true,
toJSON: {
virtuals: true,
transform: (_doc, ret) => {
ret.id = ret._id.toString();
delete ret._id;
return ret;
},
},
}
);
gardenSchema.index({ coordinates: '2dsphere' });
gardenSchema.index({ name: 'text', description: 'text', address: 'text', neighborhood: 'text', city: 'text' });
gardenSchema.index({ city: 1, neighborhood: 1 });
module.exports = mongoose.model('Garden', gardenSchema);