Skip to content

Commit 2a47d72

Browse files
chore(NODE-4171): add timestamp breaking change to 4_0_0 migration notes (#3208)
1 parent 6e2e27f commit 2a47d72

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

etc/notes/CHANGES_4.0.0.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,26 @@ const md5 = await new Promise((resolve, reject) => {
324324
await db.collection('fs.files').updateOne({ _id }, { $set: { md5 } });
325325
```
326326

327+
### BSON
328+
329+
> Updated April 4th, 2022
330+
331+
This version includes an upgrade from js-bson 1.x to js-bson 4.x.
332+
333+
#### Timestamps math operations return Javascript `Long`s
334+
335+
In versions prior to 4.x of the BSON library, Timestamps were represented with a custom class. In version 4.x of the BSON library, the Timestamp class was refactored to
336+
be a subclass of the Javascript Long class. As a result of this refactor, math operations on Timestamp objects now return Long objects instead of Timestamp objects.
337+
338+
Math operations with Timestamps is not recommended. However, if Timestamp math must be used, the old behavior can be replicated by using the Timestamp
339+
constructor, which takes a Long as an argument.
340+
341+
```typescript
342+
const four = Timestamp.fromNumber(4);
343+
const five = Timestamp.fromNumber(5);
344+
const nine = new TimeStamp(four.add(five));
345+
```
346+
327347
## Intentional Breaking Changes
328348

329349
- [`NODE-3368`](https://jira.mongodb.org/browse/NODE-3368): make name prop on error classes read-only ([#2879](https://github.com/mongodb/node-mongodb-native/pull/2879))

0 commit comments

Comments
 (0)