Skip to content

Commit

Permalink
Refactor a relevant example in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammad0-0ahmad committed Jul 19, 2022
1 parent f5983e6 commit 507823c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/guide.md
Expand Up @@ -341,6 +341,23 @@ And what if you want to do some extra processing on the name, like
define a `fullName` property that won't get persisted to MongoDB.

```javascript
// That can be done either by adding it to schema options:
const personSchema = new Schema({
name: {
first: String,
last: String
}
},{
virtuals:{
fullName:{
get() {
return this.name.first + ' ' + this.name.last;
}
}
}
});

// Or by using the virtual method as following:
personSchema.virtual('fullName').get(function() {
return this.name.first + ' ' + this.name.last;
});
Expand Down

0 comments on commit 507823c

Please sign in to comment.