Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add JSON serialization
  • Loading branch information
baileympearson committed Apr 5, 2024
commit 78c84afd7d358992093ca0f813114531f509a0b5
6 changes: 5 additions & 1 deletion src/sdam/topology_description.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ObjectId } from '../bson';
import { EJSON, type ObjectId } from '../bson';
import * as WIRE_CONSTANTS from '../cmap/wire_protocol/constants';
import { type MongoError, MongoRuntimeError } from '../error';
import { compareObjectId, shuffle } from '../utils';
Expand Down Expand Up @@ -342,6 +342,10 @@ export class TopologyDescription {
hasServer(address: string): boolean {
return this.servers.has(address);
}

toJSON() {
return EJSON.serialize(this);
}
}

function topologyTypeForServerType(serverType: ServerType): TopologyType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('TopologyDescription (integration tests)', function () {
expect(description).to.exist;

const { servers } = JSON.parse(JSON.stringify(description));
expect(Object.keys(servers).length > 0).to.be.true;
expect(Object.keys(servers).length > 0, '`servers` stringified with no servers.').to.be.true;
});
});
});