Skip to content

Querying subdocuments using whereIn by "_id" field does not work, yet it does by "id" key #2489

Closed
@fidan-mkdir

Description

@fidan-mkdir

Description:

Querying using whereIn("subarray._id", [...]) does not work, when subarray has an array of items with '_id' field. If you had subarray of items with 'id' instead of '_id' and then queried for "subarray.id" it would work.
However querying using whereRaw(['subarray._id' => ['$in' => ['id_value'']]]) works as expected. I tried transforming the array of _id strings into an array of ObjectIds but it didn't help.

Steps to reproduce

  1. Create a document with a subarray of items where each item will have an _id field
  2. Try a query using whereIn("subarray._id", [...]) = will not return results
  3. Now do the same but create a document with a subarray of items where each item will have an id field
  4. Try a query using whereIn("subarray.id", [...]) = will return results

Expected behaviour

It should work as normal, as in step 4

Actual behaviour

It returned no results while there definitely were matches

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions