Advanced custom schema type for custom objects or value-objects
See original GitHub issueI couldn’t find any example of an advanced custom schema type involving custom objects (or value-objects) in Mongoose >=4.4.
I already posted a question on StackOverflow without success: http://stackoverflow.com/questions/38094817/mongoose-advanced-custom-schema-object-type.
Resuming, how can I achieve that:
- Every time a new model is “hydrated” from db (mongoose init), the field will be an instance of my custom object and not a plain object. For this I understand it will use the
SchemaType.prototype.cast
function. - Every time I will save my Model the custom type field should be encoded and stored in a custom way (as plain object, array, string or any BSON type).
- If I use
model.toObject()
it will recursively call themodel.myfield.toObject()
to have a full plain object representation of the document.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7
Top Results From Across the Web
node.js - Mongoose advanced custom schema object type
To customize mongodb persistence, I had to implement a toBSON() function in my custom type object prototype (i.e. Polygon ). model.toObject() / ...
Read more >Creating a schema for a custom object
A schema defines the named properties of a custom object. The schema doesn't contain information about any specific object. It just describes the...
Read more >Custom field object type and Jira Automation - Forge
Hello, I am trying to use Custom field object types with Jira Automation and smart values. For example, I would like a “Create...
Read more >Schema Builder Custom Object Definition - Salesforce Help
Makes the data in the custom object records available for reporting purposes. To create reports on custom objects, choose the Other Reports report...
Read more >Advanced field value conversion using custom mapping types
We create a simple entity with a field $point which holds a value object Point representing the latitude and longitude of the position....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I added the toBSON() check in 1a93d1f. Here’s a better example of how to do the polygon type you’re looking at:
Output:
@NikhilAshodariya I opened up a separate issue for this #6174.