Skip to content

Commit 9277420

Browse files
committed
docs(document): fix code sample that errors with "Cannot set properties of undefined"
Fix #15584
1 parent 444d941 commit 9277420

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/document.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4070,15 +4070,17 @@ Document.prototype.$__toObjectShallow = function $__toObjectShallow(schemaFields
40704070
*
40714071
* If you want to skip transformations, use `transform: false`:
40724072
*
4073-
* schema.options.toObject.hide = '_id';
4074-
* schema.options.toObject.transform = function (doc, ret, options) {
4075-
* if (options.hide) {
4076-
* options.hide.split(' ').forEach(function (prop) {
4077-
* delete ret[prop];
4078-
* });
4073+
* schema.options.toObject = {
4074+
* hide: '_id',
4075+
* transform: function(doc, ret, options) {
4076+
* if (options.hide) {
4077+
* options.hide.split(' ').forEach(function(prop) {
4078+
* delete ret[prop];
4079+
* });
4080+
* }
4081+
* return ret;
40794082
* }
4080-
* return ret;
4081-
* }
4083+
* };
40824084
*
40834085
* const doc = new Doc({ _id: 'anId', secret: 47, name: 'Wreck-it Ralph' });
40844086
* doc.toObject(); // { secret: 47, name: 'Wreck-it Ralph' }

0 commit comments

Comments
 (0)