I defined:
- a mongoose schema (Type1) to save an object
- 2 others that extends the first schema (Type2 and Type3) with other properties (content, and others…).
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
Type1schema will have properties ofType1schema.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
Type1using only properties. The method you can try using (didn’t test it) isobject.getValue('content');. Also, I think thatobject._docholds the real data from DB.One last thing:
object.toStringis actually overriden and it showsinspectof entire object. That’s why you see the underlying data.