I defined:
When I load an object Type1 saved as Type 2 from the database, I can access all properties except for one (The content property). But if I do an object.toString()
the property does exist.
How is this possible?
Thanks.
Properties of mongoose objects are always the same as its schema. Loaded as a Type1
schema will have properties of Type1
schema.
The underlying data may be bigger (because of Schema inheritance or simply because someone stored more data directly in MongoDB), but you cannot access it from the level of Type1
using only properties. The method you can try using (didn't test it) is object.getValue('content');
. Also, I think that object._doc
holds the real data from DB.
One last thing: object.toString
is actually overriden and it shows inspect
of entire object. That's why you see the underlying data.