Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-4680

Allow bson to apply transforms on fields during CRUD operations based on field type and/or name

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • 2

      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.

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            c.inaciomatheus@gmail.com Matheus "Set" Inacio
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: