-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: 4.0.0, 4.1.0
-
Component/s: None
-
Empty show more show less
-
Not Needed
I have traced a behavior change back to this PR - https://github.com/mongodb/node-mongodb-native/pull/2619. It changes the return value of findOne when no results are found. It used to be null (when using driver 3.x for example) but is now undefined. I found this when debugging broken tests that expected "not found" return value to be strictly null.
Here is the latest code I am referring to - see https://github.com/mongodb/node-mongodb-native/blame/b67af3cd8b094218ec323b23e9950151cb91f1ef/src/operations/find_one.ts#L35. Pretty clearly, even when item is null, it will always be returned as undefined:
// Return the item
cursor.next((err, item) => {
{{ if (err != null) return callback(err);}}
callback(undefined, item || undefined);
});
This used to be (change made 9 months ago), which returned item directly:
// Return the item
{{ cursor.next((err, item) => {}}
if (err != null) return callback(new MongoError(err));
callback(undefined, item);
{{ });}}
The documentation I can find indicates null should be returned when no results are found (and there was no error). Asking if this change is intentional feels silly, because it must be. I would like to understand more about this change and see if there is any newer documentation that I am missing. Thank you to anyone who can help me here!
- is caused by
-
NODE-2809 Refactor Cursor and CoreCursor into common AbstractCursor class
- Closed