Skip to content
8 changes: 8 additions & 0 deletions src/change_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ export interface ChangeStreamDocumentCommon {
*/
clusterTime?: Timestamp;

/**
* The server date and time of the database operation.
* wallTime differs from clusterTime in that clusterTime is a timestamp taken from the oplog entry associated with the database operation event.
* The format is "YYYY-MM-DD HH:MM.SS.millis".
* @sinceServerVersion 6.0.0
*/
wallTime?: Date;

/**
* The transaction number.
* Only present if the operation is part of a multi-document transaction.
Expand Down
20 changes: 20 additions & 0 deletions test/integration/change-streams/change_stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,26 @@ describe('Change Streams', function () {
}
});

it('contains a wallTime date property on the change', {
metadata: { requires: { topology: 'replicaset', mongodb: '>=6.0.0' } },
async test() {
const collection = db.collection('wallTimeTest');
const changeStream = collection.watch(pipeline);

const willBeChanges = on(changeStream, 'change');
await once(changeStream.cursor, 'init');

await collection.insertOne({ d: 4 });

const change = (await willBeChanges.next()).value[0];

await changeStream.close();

expect(change).to.have.property('wallTime');
expect(change.wallTime).to.be.instanceOf(Date);
}
});

it('should create a ChangeStream on a collection and emit change events', {
metadata: { requires: { topology: 'replicaset' } },
async test() {
Expand Down
1 change: 1 addition & 0 deletions test/types/change_stream.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ expectType<ResumeToken>(change._id);
expectType<Timestamp | undefined>(change.clusterTime);
expectType<number | undefined>(change.txnNumber); // Could be a Long if promoteLongs is off
expectType<ServerSessionId | undefined>(change.lsid);
expectType<Date | undefined>(change.wallTime);

type CrudChangeDoc =
| ChangeStreamInsertDocument<Schema> // C
Expand Down