Skip to content

Commit 003246f

Browse files
committedSep 20, 2024·
Update migrating_to_6.md
1 parent becd799 commit 003246f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
 

‎docs/migrating_to_6.md

+17
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ If you're still on Mongoose 4.x, please read the [Mongoose 4.x to 5.x migration
5252
* [`toObject()` and `toJSON()` Use Nested Schema `minimize`](#toobject-and-tojson-use-nested-schema-minimize)
5353
* [TypeScript changes](#typescript-changes)
5454
* [Removed `reconnectTries` and `reconnectInterval` options](#removed-reconnecttries-and-reconnectinterval-options)
55+
* [Lodash `.isEmpty()` returns false for ObjectIds](#lodash-object-id)
5556

5657
<h2 id="version-requirements"><a href="#version-requirements">Version Requirements</a></h2>
5758

@@ -541,3 +542,19 @@ The `reconnectTries` and `reconnectInterval` options have been removed since the
541542

542543
The MongoDB node driver will always attempt to retry any operation for up to `serverSelectionTimeoutMS`, even if MongoDB is down for a long period of time.
543544
So, it will never run out of retries or try to reconnect to MongoDB.
545+
546+
547+
<h2 id="lodash-object-id"><a href="#lodash-object-id">Lodash <code>.isEmpty()</code> returns true for ObjectIds</h2>
548+
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()`.
551+
552+
An ObjectId in mongoose is never empty, so if using lodash here is a workaround when dealing with ObjectIds:
553+
554+
```javascript
555+
if (!(a instanceof Types.ObjectId) && (_.isEmpty(a) || !Types.ObjectId.isValid(a))) {
556+
throw new Error('Error.');
557+
}
558+
```
559+
560+

0 commit comments

Comments
 (0)
Please sign in to comment.