[Mongo] Filtering on a relation with "AND" doesn't work properly.
I was trying to filter on a relation attribute using AND and I got zero results. I believe it's a bug in mongo connector. I tried it with MySQL on Prisma cloud (prisma 1.32.0-beta) and it worked fine as I expected.
To reproduce
- Create the two models.
type Blog {
id: ID! @id
name: String!
labels: [Label!]! @relation(name: "BlogLabels", link: INLINE)
}
type Label {
id: ID! @id
name: String! @unique
}
- Create two labels
mutation {
l1: createLabel(data:{
name: "x"
}) {
name
}
l2: createLabel(data:{
name: "y"
}) {
name
}
}
- Create a blog
mutation {
createBlog(data:{
name: "blog"
labels: {
connect: [
{ name: "x" },
{ name: "y" }
]
}
}) {
name
labels {
name
}
}
}
- Run this query
query {
q1: blogs(where: {
labels_some:{
name: "x"
},
AND:{
labels_some:{
name: "y"
}
}
}) {
name
}
}
The result will be
{
"data": {
"q1": [
{
"name": []
}
]
}
Expected behavior
{
"data": {
"q1": [
{
"name": "blog"
}
]
}
}
Versions:
- Connector: [
MongoDB] - Prisma Server: [
1.32.2] -
prismaCLI: [prisma/1.32.2 (linux-x64) node-v10.15.3] - OS: [
Ubuntu 18.04]
Closing as a duplicate of https://github.com/prisma/prisma/issues/3943.
I think you are not understanding the API correctly, read the above issue and try this query:
query {
q1: blogs(
where: {
AND: [{ labels_some: { name: "x" } }, { labels_some: { name: "y" } }]
}
) {
name
}
}
Also, you said that this worked with MySQL which shouldn't be the case. Can you please a screenshot of the query?
@pantharshit00 I got your point, but I don't understand what is wrong with my query?
- When I write a query like
query {
blogs {
where: {
name_contains: "something",
labels_some: { name: "x" }
}
}
}
I am expecting an ANDing of all conditions inside the where clause (name_contains and labels_some). In addition, AND can take either an array or a single element. Accordingly, a query like
query {
blogs {
where: {
name_contains: "something",
labels_some: { name: "x" },
AND: [{ labels_some: { name: "y" } }, { labels_some: { name: "z" } }]
}
}
}
should return the blogs whose:
- name contains "something"
- labels contain a label with name "x"
- labels contain a label with name "y" and a label with name "z"
So, I think my query should work fine.
Here is a screenshot from SQL connector which produced the output I expected.

If my understanding for the query is not correct, can you elaborate for me its semantics so that it will return an empty list? And why is it different from SQL connector?
@pantharshit00 your query didn't work as well using mongo connector

This is indeed a bug @AhmadElsagheer . Thanks for the detailed reproduction. It is specific to our implementation of relations in Mongo and should only occur there. We're working on a fix.