-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Closed
Labels
enhancementThis issue is a user-facing general improvement that doesn't fix a bug or add a new featureThis issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Milestone
Description
I played i bit with toObject method and found, that minimize: true flag is being ignored when getters: true is set:
{Schema} = mongoose = require 'mongoose'
ObjectId = Schema.ObjectId
Element = mongoose.model 'Element', new Schema
field1: String
field2: String
nested: field: String
doc = new Element field1: 'foo'
console.log 'nice', doc.toObject minimize: yes
console.log 'ugly', doc.toObject minimize: yes, getters: yesnice { field1: 'foo', _id: 51fa92d61061e9ce7e000001 }
ugly { field1: 'foo',
_id: 51fa92d61061e9ce7e000001,
id: '51fa92d61061e9ce7e000001',
__v: undefined,
nested: { field: undefined },
field2: undefined }
It's not a problem for top-level fields, because JSON serialization removes such fields. But nested field becomes an empty object, which is not what I want to send to the client:
{ field1: 'foo',
_id: '51fa9436bd6afbc707000001',
id: '51fa9436bd6afbc707000001',
nested: {} }
It's not only about the amount of data I'm sending. For most client side frameworks {} means that my document has a nested sub-document, which is not true.
Metadata
Metadata
Assignees
Labels
enhancementThis issue is a user-facing general improvement that doesn't fix a bug or add a new featureThis issue is a user-facing general improvement that doesn't fix a bug or add a new feature