• Converts a BSON document to an Extended JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.


    • value: SerializableTypes

      The value to convert to extended JSON

    • Optional replacer: (string | number)[] | Options | ((this, key, value) => any)

      A function that alters the behavior of the stringification process, or an array of String and Number objects that serve as a whitelist for selecting/filtering the properties of the value object to be included in the JSON string. If this value is null or not provided, all properties of the object are included in the resulting JSON string

    • Optional space: string | number

      A String or Number object that's used to insert white space into the output JSON string for readability purposes.

    • Optional options: Options

      Optional settings

    Returns string


    const { EJSON } = require('bson');
    const Int32 = require('mongodb').Int32;
    const doc = { int32: new Int32(10) };

    // prints '{"int32":{"$numberInt":"10"}}'
    console.log(EJSON.stringify(doc, { relaxed: false }));

    // prints '{"int32":10}'

Generated using TypeDoc