-
Type: New Feature
-
Resolution: Unresolved
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
How are you using Mongo? What version of the server and driver are you using?
Node driver 4.10.0
What is the feature/improvement you would like?
- Make it possible to apply transforms on fields based
- on field type, or
- field name
- On Read operations should be simple and already covers the use case I have in mind, but depending on the complexity could be useful to have it on other CRUD operations
- Probably should be in bson, during serialization or deserialization
What use case would this feature/improvement enable?
There are maybe more, but the use case we're facing at the moment is:
- We want to duplicate objects
- They are highly related, in the sense that:
- They have relationships represented by materialized paths, or
- Deeply nested fields that represent an ID of another object
- When duplicating, we want to generate new IDs, either by rehashing or a random new ID, but those IDs need to be relatable to each other
- i.e: foo mentions bar in its materialized path, foo duplicate should now mention bar duplicate's ID in its materialized path, not the original
- If we could apply a transformation to any field that is an ObjectId or a string, for example, we could:
- preemptively generate new IDs for the objects that will be copied
- create a map of oldId->newId
- have the transformation substitute any oid that has a matching new ID or has the ID as text in a materialized path, via RegEx
- we also could regenerate any field that has an unique index constraint, such as user.email
These transformations could possibly be around parser/deserializer.ts:717
The current implementation I did is a work-around using EJSON, stringifying, performing regex substitution, then parsing back, but it'd be far better to have it happen there, on the spot, before the object is returned.
I could probably develop this feature and contribute to the project if deemed reasonable.