I realized I was using the short syntax of $toObjectId, which didn’t have the options of onNull, or onError.

I needed to revert back to $convert:

{$convert: {input: '$Company', to : 'objectId', onError: '',onNull: ''}}

Source

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top