You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/typescript/schemas.md
+19-4
Original file line number
Diff line number
Diff line change
@@ -164,7 +164,7 @@ This is because Mongoose has numerous features that add paths to your schema tha
164
164
## Arrays
165
165
166
166
When you define an array in a document interface, we recommend using vanilla JavaScript arrays, **not** Mongoose's `Types.Array` type or `Types.DocumentArray` type.
167
-
Instead, use the `THydratedDocumentType` generic to define that the hydrated document type has paths of type `Types.Array` and `Types.DocumentArray`.
167
+
Instead, use the `THydratedDocumentType` generic for models and schemas to define that the hydrated document type has paths of type `Types.Array` and `Types.DocumentArray`.
168
168
169
169
```typescript
170
170
importmongoosefrom'mongoose'
@@ -178,17 +178,27 @@ interface IOrder {
178
178
// for fully hydrated docs returned from `findOne()`, etc.
Use `HydratedArraySubdocument<RawDocType>` for the type of array subdocuments, and `HydratedSingleSubdocument<RawDocType>` for single subdocuments.
222
+
223
+
If you are not using [schema methods](../guide.html#methods), middleware, or [virtuals](../tutorials/virtuals.html), you can omit the last 7 generic parameters to `Schema()` and just define your schema using `new mongoose.Schema<IOrder, OrderModelType>(...)`.
224
+
The THydratedDocumentType parameter for schemas is primarily for setting the value of `this` on methods and virtuals.
0 commit comments