Looking to retrieve some Documents based on a field that may exist in an array if a filter is applied. However, I also need to ensure that the same field does not equal null unconditionally. While using $in: [some values] can prevent null from being included, the challenge lies in creating a conditional query based on whether a filter is set or not.
Is there a more efficient approach to achieving the same outcome as below? Would it even work?
db.Parents.fetch({
childId: { $in: childIds },
childId: { $ne: null }
});