-
Notifications
You must be signed in to change notification settings - Fork 0
/
Product.model.ts
51 lines (46 loc) · 1.01 KB
/
Product.model.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const mongoose = require("mongoose");
mongoose.set("useCreateIndex", true);
const ProductSchema = new mongoose.Schema({
name: {
type: String,
required: true,
},
price: {
type: Number,
required: true,
},
weight: {
type: Number,
required: true,
},
images: [{ type: String, required: true }],
description: { type: String, required: false },
shopName: { type: String, required: true },
likes: { type: Number, required: true },
location: {
type: {
type: String,
required: true,
},
coordinates: [{ type: Number, required: true }],
},
status: { type: String, required: true },
shopID: { type: mongoose.Types.ObjectId, required: true },
});
ProductSchema.index({
name: "search",
mappings: {
dynamic: false,
fields: {
location: {
type: "geo",
},
name: {
type: "string",
analyzer: "lucene.italian",
},
},
},
});
const Product = mongoose.model("product", ProductSchema);
export default Product;