How to use the bson.EJSON.stringify function in bson

To help you get started, we’ve selected a few bson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mongodb / stitch-js-sdk / packages / core / sdk / __tests__ / internal / EJSONUnitTests.ts View on Github external
it("should stringify Extended JSON correctly", () => {
    expect(
      EJSON.stringify({
        test: 42
      }, { relaxed: false })
    ).toEqual('{"test":{"$numberInt":"42"}}');
  });
  it("should deserialize Extended JSON correctly", () => {
github mongodb / stitch-js-sdk / packages / core / sdk / src / services / internal / CoreStitchServiceClientImpl.ts View on Github external
private getStreamServiceFunctionRequest(
    name: string,
    args: any[]
  ): StitchAuthRequest {
    const body = { name };
    if (this.serviceName !== undefined) {
      body[this.serviceField] = this.serviceName;
    }
    body[this.argumentsField] = args;

    const reqBuilder = new StitchAuthRequest.Builder();
    reqBuilder
      .withMethod(Method.GET)
      .withPath(this.serviceRoutes.functionCallRoute +
        `?stitch_request=${encodeURIComponent(base64Encode(EJSON.stringify(body)))}`);
    return reqBuilder.build();
  }
github webiny / webiny-js / packages / webiny-cli / src / database / index.js View on Github external
async execute(query) {
        try {
            const payload = EJSON.stringify({
                query,
                database: { server: this.server, name: this.databaseName }
            });

            const res = await fetch(process.env.MONGO_HTTP_SERVER, {
                method: "post",
                body: payload,
                headers: { "Content-Type": "application/json" }
            });

            if (res.status >= 400) {
                throw new Error("Bad response from server");
            }

            const data = await res.text();
            return EJSON.parse(data).result;
github mongodb / stitch-js-sdk / packages / core / sdk / src / internal / net / StitchDocRequest.ts View on Github external
public build(): StitchDocRequest {
      if (this.document === undefined || !(this.document instanceof Object)) {
        throw new Error("document must be set");
      }
      if (this.headers === undefined) {
        this.withHeaders({});
      }
      this.headers![Headers.CONTENT_TYPE] = ContentTypes.APPLICATION_JSON;
      this.withBody(EJSON.stringify(this.document, { relaxed: false }));
      return new StitchDocRequest(super.build(), this.document);
    }
  }
github mongodb / stitch-js-sdk / packages / core / admin-client / src / Resources.ts View on Github external
protected _create<u>(data: U, type: TypeCtor<u>): Promise<u> {
    const reqBuilder = new StitchAuthRequest.Builder();
    reqBuilder
      .withMethod(Method.POST)
      .withPath(this.url)
      .withBody(EJSON.stringify(serialize(data), { relaxed: false }));
    return this.adminAuth
      .doAuthenticatedRequest(reqBuilder.build())
      .then(response =&gt; 
        deserialize(EJSON.parse(response.body!), type)
      );
  }
</u></u></u>
github mongodb / stitch-js-sdk / packages / core / admin-client / src / Resources.ts View on Github external
protected _update(data: T, putOrPatch: Method.PATCH | Method.PUT): Promise {
    const reqBuilder = new StitchAuthRequest.Builder();
    reqBuilder
      .withMethod(putOrPatch)
      .withPath(this.url)
      .withBody(EJSON.stringify(serialize(data), { relaxed: false }));

    return this.adminAuth
      .doAuthenticatedRequest(reqBuilder.build())
      .then((response) =&gt; {
        return; 
      });
  }
github mongodb / stitch-js-sdk / packages / core / sdk / src / internal / net / StitchAuthDocRequest.ts View on Github external
public build(): StitchAuthDocRequest {
      if (this.document === undefined || !(this.document instanceof Object)) {
        throw new Error("document must be set: " + this.document);
      }

      if (this.headers === undefined) {
        this.withHeaders({});
      }

      this.headers![Headers.CONTENT_TYPE] = ContentTypes.APPLICATION_JSON;

      this.withBody(EJSON.stringify(this.document, { relaxed: false }));
      return new StitchAuthDocRequest(super.build(), this.document);
    }
  }