Skip to content

Misleading error message when filtering with _id: { $exists: <boolean> } in collections #2325

@toptobes

Description

@toptobes

Example (the same holds when using $exists: false or having other fields in the filter as well):

command: {
  deleteMany: { filter: { _id: { '$exists': true } } }
},
rawResponse: {
  errors: [
    {
      message: 'Invalid filter expression: $exists operator must have `BOOLEAN`',
      errorCode: 'INVALID_FILTER_EXPRESSION',
      id: '7a94d466-e9eb-4cef-8153-0454c65522d6',
      family: 'REQUEST',
      title: 'Invalid filter expression',
      scope: 'FILTER'
    }
  ]
}

Using $exists on other fields doesn't seem to cause issues (e.g. { other_field: { $exists: true } }).

I haven't extensively tested, but I believe the issue is universal with any filter, not just on deleteMany. Here's findOne, for example, having the same issue:

command: {
  findOne: {
    filter: { _id: { '$exists': false } }
  }
},
rawResponse: {
  errors: [
    {
      message: 'Invalid filter expression: $exists operator must have `BOOLEAN`',
      errorCode: 'INVALID_FILTER_EXPRESSION',
      id: '4893310d-ed09-4af0-8463-edd71e034c2e',
      family: 'REQUEST',
      title: 'Invalid filter expression',
      scope: 'FILTER'
    }
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions