Prisma1: [Mongo] Count Aggregation Pulls Correct Nodes, Displays Incorrect Node Count

Created on 18 Apr 2019  路  7Comments  路  Source: prisma/prisma1

Describe the bug

This is the first time I'm using the aggregations API, I believe I am doing everything correctly, yet getting 0 back even though I should expect to see 1. The correct list of nodes is coming back though.

This is my query:

query Funnels {
    funnelsConnection(where:{
        shop:{
            id:"5c86a90f24aa9a0008d42d21"
        }
        archived:false
    }) {
        aggregate {
        count
        }
        edges {
            node {
                id
            }
        }
    }
}

This is the response:

```
{
"data": {
"funnelsConnection": {
"aggregate": {
"count": 0
},
"edges": [
{
"node": {
"id": "5ca64a68a7b11b0009cf5687"
}
}
]
}
}
}
````

Clearly count should be 1 but is coming back as 0. Not entirely sure if I'm not using the API correctly or if this is a real bug. Note: Even when I remove the archived: false flag, it still returns 0 even though there would be more than 1 node returned in that case. I only experience this issue when querying with an association.

To Reproduce
Steps to reproduce the behavior:

  1. Perform a count query on a child resource (Funnel in my case) filtered by a parent resource ID (Shop in my case)

Expected behavior
Given the query I've described above, count should be 1. It always returns 0 when filtering by a parent association.

Screenshots

Screenshot

Versions (please complete the following information):

  • Connector: MongoDB
  • Prisma Server: 1.28
  • prisma CLI: prisma/1.26.3 (darwin-x64) node-v8.15.0
  • OS: OSX Mojave
bu2-confirmed areconnectomongo areserver

Most helpful comment

I just merged a fix to master and this will be fixed in the next release.

All 7 comments

I was able to reproduce the bug.

image

Here is a reproduction: https://github.com/pantharshit00/prisma-issue-4414

cc @do4gr, this issue is specific to mongo, postgres connector doesn't have this issue as seen in the screenshot, maybe use that as a workaround for the time being:
image

Thanks for the detailed reproduction. We have a fix and will release it to master soon.

@do4gr Did this issue fixed in 1.32.0? I still encounter aggregation count error in the latest version.

@soqt

Have you upgraded you prisma instance in your Docker container? You will need to upgrade your cli as well as prisma server.

@soqt

Have you upgraded you prisma instance in your Docker container? You will need to upgrade your cli as well as prisma server.

Yes I did. For this example, the new version works as expected. However, when "where" selector contains ObjectId, it fails.

For example I have a User & Company datatype

type User {
  id: ID! @id
  company: Company
}
type Company {
  id: ID! @id
  name: String,
  members: [User!]!
}

After create several users and companies, this query results aggregate count 0 although there are one edge.

{
  usersConnection(where: {
    company: {
      id: "5ccba2f2a7b11b00081e405d"
    }
  }) {
    edges {
      node {
        id
        company {
          id
        }
      }
    }
    aggregate {
      count
    }
  }
}

Screen Shot 2019-05-03 at 10 19 43 AM

I can reproduce your error @soqt and will look into it. Thanks for reporting!

I just merged a fix to master and this will be fixed in the next release.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nikolasburk picture nikolasburk  路  3Comments

marktani picture marktani  路  3Comments

ragnorc picture ragnorc  路  3Comments

jannone picture jannone  路  3Comments

hoodsy picture hoodsy  路  3Comments