import { mongo } from "https://deno.land/x/hex@0.5.15/src/data/deps.ts";
const { stringify } = mongo.Bson.EJSON;
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.
Examples
Example 1
Example 1
const { EJSON } = require('bson');
const Int32 = require('mongodb').Int32;
const doc = { int32: new Int32(10) };
// prints '{"int32":{"$numberInt":"10"}}'
console.log(stringify(doc, { relaxed: false }));
// prints '{"int32":10}'
console.log(stringify(doc));
Parameters
value: SerializableTypes
- The value to convert to extended JSON
optional
replacer: (number | string)[] | ((this: any,
key: string,
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
- 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