prisma.exists method not working with mongodb Atlas

2k views Asked by At

i am using prisma image 1.34 I have a small issue trying to implement the prisma.exists method with mongodb atlas.

type Business {
  _id: ID! @id
  name: String!
  desc: String!
  published: Boolean!
  author: User! @relation(name: "BusinessUser", link: INLINE)
async updateBusiness(parent, args, { prisma, request }, info) {

        const postExists = await prisma.exists.Business({
            _id: args.id,
        })

        if (!postExists) {
            throw new Error('Unable to update post')
        }


        return prisma.mutation.updateBusiness({
            where: {
                _id: args.id
            },
            data: args.data
        }, info)
    }
}

the error I got is

TypeError: Cannot read property 'length' of undefined
    at C:\Users\jarid\Desktop\Alfarouk\alfarouq\Backend\node_modules\prisma-binding\src\Prisma.ts:86:31
    at process._tickCallback (internal/process/next_tick.js:68:7)

when I remove the code related to prisma.exists the resolver runs successfully , also I did verify that the argument "args.id" is pulled successfully

**Versions

Prisma Server: [1.34.1]
prisma CLI: [1.34.1 ] 
OS: [Windows 10 home edition]
docker toolbox
2

There are 2 answers

3
realAlexBarge On

Are you using the client or the bindings? According to the prisma documentation the syntax should be as follows:

const userExists = prisma.$exists.user({
  id: 'cjli6tko8005t0a23fid7kke7',
})

See: https://www.prisma.io/docs/1.34/prisma-client/features/check-existence-JAVASCRIPT-pyl1/

0
Shrish Ankit On

I had the same problem. The Documentation is not correct. The exists function is called in the wrong way.

Try this. it should work...

const userExists = prisma.user({
id: 'cjli6tko8005t0a23fid7kke7',
}).$exists