Skip to content

Commit

Permalink
docs: update oid deprecation migration
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Nov 30, 2022
1 parent 98eff70 commit 685a6d0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions docs/upgrade-to-v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,17 @@ This library no longer polyfills [ES Map](https://developer.mozilla.org/en-US/do
The following deprecated methods have been removed:

- `ObjectId.prototype.generate`
- Instead, generate a new ObjectId with the constructor: `new ObjectId()`
- Instead, generate a new ObjectId with the constructor: `new ObjectId()` or using the `static generate(time?: number)` method.
- `ObjectId.prototype.generationTime`
- Instead, use `static createFromTime()` and `getTimestamp()` to set and inspect these values on an `ObjectId()`

- `ObjectId.prototype.getInc`
- `ObjectId.prototype.get_inc`
- `ObjectId.get_inc`
- The `static getInc()` is private now since it has a side effect of changing the value of the next `ObjectId` generated, using `new ObjectId()` and inspecting the increment section of the bytes can provide insight into the current increment value.
- The `static getInc()` is private since invoking it increments the next `ObjectId` index, instead users should inspect the counter on newly created ObjectId if it is needed.
- See the following code snippet for how to obtain the counter field of an ObjectId:

- `ObjectId.prototype.generationTime`
- Instead, use `static createFromTime()` and `getTimestamp()` to set and inspect these values on an `ObjectId()`
```ts
const oid = new ObjectId();
const counterField = oid.id[9] << 16 | oid.id[10] << 8 | oid.id[11];
```

0 comments on commit 685a6d0

Please sign in to comment.