Skip to content

Commit f86bda7

Browse files
committedSep 23, 2024·
quick clarification
1 parent f45e28c commit f86bda7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed
 

‎docs/migrating_to_6.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -546,14 +546,15 @@ So, it will never run out of retries or try to reconnect to MongoDB.
546546

547547
<h2 id="lodash-object-id"><a href="#lodash-object-id">Lodash <code>.isEmpty()</code> returns true for ObjectIds</h2>
548548

549-
Lodash's `isEmpty()` function returns true for primitives and primitive wrappers. `ObjectId()` is an object wrapper that is treated as a primitive by Mongoose.
550-
As a result, `isEmpty()` will return `true` for `ObjectId()`.
549+
Lodash's `isEmpty()` function returns true for primitives and primitive wrappers.
550+
`ObjectId()` is an object wrapper that is treated as a primitive by Mongoose.
551+
But starting in Mongoose 6, `_.isEmpty()` will return true for ObjectIds because of Lodash implementation details.
551552

552-
An ObjectId in mongoose is never empty, so if using lodash here is a workaround when dealing with ObjectIds:
553+
An ObjectId in mongoose is never empty, so if you're using `isEmpty()` you should check for `instanceof ObjectId`.
553554

554555
```javascript
555-
if (!(a instanceof Types.ObjectId) && (_.isEmpty(a) || !Types.ObjectId.isValid(a))) {
556-
throw new Error('Error.');
556+
if (!(val instanceof Types.ObjectId) && _.isEmpty(val)) {
557+
// Handle empty object here
557558
}
558559
```
559560

0 commit comments

Comments
 (0)
Please sign in to comment.