0

I'm trying to find documents where the boxId field is not set or empty.

Running this does not work:

return Items.find({ createdBy: currenUser, boxId: { $or: [{ $exists: false }, { $size: 0 }] } })

Here's the error I get on the console:

Exception in template helper: Error: Unrecognized operator: $or
Fábio Queluci
  • 311
  • 1
  • 2
  • 15

1 Answers1

2

The ordering of mongodb key names and operators can often be confusing. Put the $or before the field conditions:

return Items.find({ createdBy: currentUser,
  $or: [
    { boxId: { $exists: false }},
    { boxId: "" }}
  ]
});
Michel Floyd
  • 18,793
  • 4
  • 24
  • 39