Query a parent child relationship by objectids

Hi @Gordian, and welcome to the forum!

Not familiar at all with mongoDB, but this issue is similar also with postgres. I found the below conversation, which is the inverse of what you're trying to achieve.

Which makes me think that you may need to stringify the variable, e.g. {{ JSON.stringify( listProcesses.selectedRow.subprocess_ids ) }} ?

However, this will end up being

{"_id": {$in: [{$oid: "687a69d478b4bc14f555f596","687a69d478b4bc14f555f597"}] } }

rather than

{"_id": {$in: [{$oid: "687a69d478b4bc14f555f596"}, {$oid:"687a69d478b4bc14f555f597"}] } }

So I think the solution may be the below:

{
  "_id": {
    "$in": {{ listProcesses.selectedRow.subprocess_ids.map(id => ({ $oid: id })) }}
  }
}
1 Like