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

EJSON prevents replacer from working on unsupported values

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: EJSON

      What problem are you facing?

      EJSON.stringify mirrors JSON.stringify and accepts a replacer that should allow non-EJSON-ifyable values to be replaced with something that is. Unfortunately the serializeValue routine is run first so information about the value is lost by the time it reached the replacer.

      The desired use case is to add a simple replacer that supports es6 Map and Set, but when the replacer is called Maps become an empty object.

      What driver and relevant dependency versions are you using?

      BSON 4.x

      Steps to reproduce?

      You can see below that in the JSON api the callback is given a reference to the Map:

      > JSON.stringify( {m: new Map()}, (k,v) => {console.log('k:', k, 'v:',v); return v;})
      k:  v: { m: Map(0) {} }
      k: m v: Map(0) {}
      '{"m":{}}'
      > BSON.EJSON.stringify( {m: new Map()}, (k,v) => {console.log('k:', k, 'v:',v); return v;})
      k:  v: { m: {} }
      k: m v: {}
      '{"m":{}}
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: