Skip to content

Commit

Permalink
docs: add note re: #7181 and remove typePojoToMixed
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jul 29, 2021
1 parent 972b2b7 commit ec1b601
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 42 deletions.
1 change: 0 additions & 1 deletion docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ Valid options:
- [toJSON](#toJSON)
- [toObject](#toObject)
- [typeKey](#typeKey)
- [typePojoToMixed](/docs/schematypes.html#mixed)
- [useNestedStrict](#useNestedStrict)
- [validateBeforeSave](#validateBeforeSave)
- [versionKey](#versionKey)
Expand Down
14 changes: 0 additions & 14 deletions docs/schematypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,20 +387,6 @@ const Any = new Schema({ any: {} });
const Any = new Schema({ any: Object });
const Any = new Schema({ any: Schema.Types.Mixed });
const Any = new Schema({ any: mongoose.Mixed });
// Note that by default, if you're using `type`, putting _any_ POJO as the `type` will
// make the path mixed.
const Any = new Schema({
any: {
type: { foo: String }
} // "any" will be Mixed - everything inside is ignored.
});
// However, as of Mongoose 5.8.0, this behavior can be overridden with typePojoToMixed.
// In that case, it will create a single nested subdocument type instead.
const Any = new Schema({
any: {
type: { foo: String }
} // "any" will be a single nested subdocument.
}, {typePojoToMixed: false});
```

Since Mixed is a schema-less type, you can change the value to anything else you
Expand Down
17 changes: 0 additions & 17 deletions docs/subdocs.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,23 +355,6 @@ const schema = new Schema({
});
```

Surprisingly, declaring `nested` with an object `type` makes `nested`
into a path of type [Mixed](/docs/schematypes.html#mixed). To instead
make Mongoose automatically convert `type: { prop: String }` into
`type: new Schema({ prop: String })`, set the `typePojoToMixed` option
to `false`.

```javascript
const schema = new Schema({
nested: {
// Because of `typePojoToMixed`, Mongoose knows to
// wrap `{ prop: String }` in a `new Schema()`.
type: { prop: String },
required: true
}
}, { typePojoToMixed: false });
```

### Next Up

Now that we've covered Subdocuments, let's take a look at
Expand Down
8 changes: 0 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,6 @@ declare module 'mongoose' {
/** `{ transform: true, flattenDecimals: true }` by default. Overwrites default objects to `toObject()` */
toObject?: ToObjectOptions;

/** true by default, may be `false` or `true`. Sets the default typePojoToMixed for schemas. */
typePojoToMixed?: boolean;

/**
* true by default. Set to `false` to make `findOneAndUpdate()` and `findOneAndRemove()`
* use native `findOneAndUpdate()` rather than `findAndModify()`.
Expand Down Expand Up @@ -1535,11 +1532,6 @@ declare module 'mongoose' {
* field names by setting timestamps.createdAt and timestamps.updatedAt.
*/
timestamps?: boolean | SchemaTimestampsConfig;
/**
* Determines whether a type set to a POJO becomes
* a Mixed path or a Subdocument (defaults to true).
*/
typePojoToMixed?: boolean;
}

interface SchemaTimestampsConfig {
Expand Down
3 changes: 1 addition & 2 deletions lib/validoptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ const VALID_OPTIONS = Object.freeze([
'setDefaultsOnInsert',
'strict',
'toJSON',
'toObject',
'typePojoToMixed'
'toObject'
]);

module.exports = VALID_OPTIONS;
2 changes: 2 additions & 0 deletions migrating_to_6.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

* Mongoose now passes the document as the first parameter to `default` functions. This may affect you if you pass a function that expects different parameters to `default`, like `default: mongoose.Types.ObjectId`. See [gh-9633](https://github.com/Automattic/mongoose/issues/9633)

* Schema paths declared with `type: { name: String }` become single nested subdocs in Mongoose 6, as opposed to Mixed in Mongoose 5. This removes the need for the `typePojoToMixed` option. See [gh-7181](https://github.com/Automattic/mongoose/issues/7181).

* When populating a subdocument with a function `ref` or `refPath`, `this` is now the subdocument being populated, not the top-level document. See [#8469](https://github.com/Automattic/mongoose/issues/8469)

* Single nested subdocs have been renamed to "subdocument paths". So `SchemaSingleNestedOptions` is now `SchemaSubdocumentOptions` and `mongoose.Schema.Types.Embedded` is now `mongoose.Schema.Types.Subdocument`. See [gh-10419](https://github.com/Automattic/mongoose/issues/10419)
Expand Down

0 comments on commit ec1b601

Please sign in to comment.