Operational Defect Database

BugZero found this defect 52 days ago.

MongoDB | 2625496

Get rid of "if obj.hasElement(field) then obj[field]" antipattern

Last update date:

3/28/2024

Affected products:

MongoDB Server

Affected releases:

No affected releases provided.

Fixed releases:

No fixed releases provided.

Description:

Info

This is an antipattern because it makes us go through the BSON object twice: if (obj.hasElement(elemName)) { elem = obj["elemName"] doStuff(elem); } Instead it should be: elem = obj["elemName"] if (!elem.eoo()) { doStuff(elem); } We do this in several places in our codebase, such as here, here, here, etc. While some of the examples I listed are not on the hot path, it would help if we got rid of this idiom altogether so that it stops spreading. See comments for more info.

Top User Comments


Steps to Reproduce


Additional Resources / Links

Share:

BugZero® Risk Score

What's this?

Coming soon

Status

Needs Scheduling

Learn More

Search:

...