質問編集履歴
3
Model(user)の記述に漏れがあったため修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -140,7 +140,7 @@
|
|
140
140
|
|
141
141
|
module.exports = mongoose.model('Product', productSchema);
|
142
142
|
|
143
|
-
|
143
|
+
|
144
144
|
|
145
145
|
```
|
146
146
|
|
@@ -198,6 +198,10 @@
|
|
198
198
|
|
199
199
|
});
|
200
200
|
|
201
|
+
|
202
|
+
|
203
|
+
module.exports = mongoose.model('User', userSchema);
|
204
|
+
|
201
205
|
```
|
202
206
|
|
203
207
|
|
2
リンク修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -206,7 +206,7 @@
|
|
206
206
|
|
207
207
|
下記ドキュメントを参照しましたが、何が間違っているのか理解できませんでした。
|
208
208
|
|
209
|
-
https://mongoosejs.com/docs/populate.html
|
209
|
+
[https://mongoosejs.com/docs/populate.html](https://mongoosejs.com/docs/populate.html)
|
210
210
|
|
211
211
|
|
212
212
|
|
1
該当コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -58,7 +58,7 @@
|
|
58
58
|
|
59
59
|
### 該当のソースコード
|
60
60
|
|
61
|
-
|
61
|
+
Contorollerの記述:
|
62
62
|
|
63
63
|
```js
|
64
64
|
|
@@ -84,6 +84,124 @@
|
|
84
84
|
|
85
85
|
|
86
86
|
|
87
|
+
Model(product)の記述:
|
88
|
+
|
89
|
+
```js
|
90
|
+
|
91
|
+
const mongoose = require('mongoose');
|
92
|
+
|
93
|
+
const Schema = mongoose.Schema;
|
94
|
+
|
95
|
+
const productSchema = new Schema({
|
96
|
+
|
97
|
+
title: {
|
98
|
+
|
99
|
+
type: String,
|
100
|
+
|
101
|
+
required: true
|
102
|
+
|
103
|
+
},
|
104
|
+
|
105
|
+
price: {
|
106
|
+
|
107
|
+
type: Number,
|
108
|
+
|
109
|
+
required: true
|
110
|
+
|
111
|
+
},
|
112
|
+
|
113
|
+
description: {
|
114
|
+
|
115
|
+
type: String,
|
116
|
+
|
117
|
+
required: true
|
118
|
+
|
119
|
+
},
|
120
|
+
|
121
|
+
imageUrl: {
|
122
|
+
|
123
|
+
type: String,
|
124
|
+
|
125
|
+
required: true
|
126
|
+
|
127
|
+
},
|
128
|
+
|
129
|
+
userId: {
|
130
|
+
|
131
|
+
type: Schema.Types.ObjectId,
|
132
|
+
|
133
|
+
ref: 'User',
|
134
|
+
|
135
|
+
required: true
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
});
|
140
|
+
|
141
|
+
module.exports = mongoose.model('Product', productSchema);
|
142
|
+
|
143
|
+
};
|
144
|
+
|
145
|
+
```
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
Model(user)の記述:
|
150
|
+
|
151
|
+
```js
|
152
|
+
|
153
|
+
const mongoose = require('mongoose');
|
154
|
+
|
155
|
+
const Schema = mongoose.Schema;
|
156
|
+
|
157
|
+
const userSchema = new Schema({
|
158
|
+
|
159
|
+
name: {
|
160
|
+
|
161
|
+
type: String,
|
162
|
+
|
163
|
+
required: true
|
164
|
+
|
165
|
+
},
|
166
|
+
|
167
|
+
email: {
|
168
|
+
|
169
|
+
type: String,
|
170
|
+
|
171
|
+
required: true
|
172
|
+
|
173
|
+
},
|
174
|
+
|
175
|
+
cart: {
|
176
|
+
|
177
|
+
items: [
|
178
|
+
|
179
|
+
{
|
180
|
+
|
181
|
+
productId: {
|
182
|
+
|
183
|
+
type: Schema.Types.ObjectId,
|
184
|
+
|
185
|
+
ref: 'Product',
|
186
|
+
|
187
|
+
required: true
|
188
|
+
|
189
|
+
},
|
190
|
+
|
191
|
+
quantity: { type: Number, required: true }
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
]
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
});
|
200
|
+
|
201
|
+
```
|
202
|
+
|
203
|
+
|
204
|
+
|
87
205
|
### 試したこと
|
88
206
|
|
89
207
|
下記ドキュメントを参照しましたが、何が間違っているのか理解できませんでした。
|