Skip to content

Commit

Permalink
docs(subdocuments): remove out-of-date section about subdocument vs n…
Browse files Browse the repository at this point in the history
…ested path declarations in Mongoose 5

Re: #12030
  • Loading branch information
vkarpov15 committed Jul 15, 2022
1 parent dfc2fd1 commit 9a09be1
Showing 1 changed file with 0 additions and 36 deletions.
36 changes: 0 additions & 36 deletions docs/subdocs.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ a group of fields (e.g. dateRange.fromDate <= dateRange.toDate).
<li><a href="#removing-subdocs">Removing Subdocs</a></li>
<li><a href="#subdoc-parents">Parents of Subdocs</a></li>
<li><a href="#altsyntaxarrays">Alternate declaration syntax for arrays</a></li>
<li><a href="#altsyntaxsingle">Alternate declaration syntax for single subdocuments</a></li>
</ul>

### What is a Subdocument?
Expand Down Expand Up @@ -319,41 +318,6 @@ const parentSchema = new Schema({
});
```

<h4 id="altsyntaxsingle"><a href="#altsyntaxsingle">Alternate declaration syntax for single nested subdocuments</a></h4>

Unlike document arrays, Mongoose 5 does not convert an objects in schemas
into nested schemas. In the below example, `nested` is a _nested path_
rather than a subdocument.

```javascript
const schema = new Schema({
nested: {
prop: String
}
});
```

This leads to some surprising behavior when you attempt to define a
nested path with validators or getters/setters.

```javascript
const schema = new Schema({
nested: {
// Do not do this! This makes `nested` a mixed path in Mongoose 5
type: { prop: String },
required: true
}
});

const schema = new Schema({
nested: {
// This works correctly
type: new Schema({ prop: String }),
required: true
}
});
```

### Next Up

Now that we've covered Subdocuments, let's take a look at
Expand Down

0 comments on commit 9a09be1

Please sign in to comment.