P
Prisma10mo ago
Zeke

Pull Operator not Existing?

await db.$transaction([
db.account.update({
where: {
id: values[0],
isPrimary: false
},
data: {
guildIds: {
push: guild_id
}
}
}),
db.account.updateMany({
where: {
NOT: {
id: values[0]
},
guildIds: {
has: guild_id
}
},
data: {
guildIds: {
pull: guild_id
}
}
})
])
await db.$transaction([
db.account.update({
where: {
id: values[0],
isPrimary: false
},
data: {
guildIds: {
push: guild_id
}
}
}),
db.account.updateMany({
where: {
NOT: {
id: values[0]
},
guildIds: {
has: guild_id
}
},
data: {
guildIds: {
pull: guild_id
}
}
})
])
Hi. For some reason, in the data of my updateMany, pull is getting this type error:
Object literal may only specify known properties, and 'pull' does not exist in type 'string[] | AccountUpdateguildIdsInput | { set?: Exact<string[] | undefined, string[] | undefined>; push?: Exact<string | string[] | undefined, string | string[] | undefined>; }'.ts(2353)
index.d.ts(4604, 5): The expected type comes from property 'guildIds' which is declared here on type 'Exact<(Without<AccountUpdateManyMutationInput, AccountUncheckedUpdateManyInput> & AccountUncheckedUpdateManyInput) | (Without<...> & AccountUpdateManyMutationInput), (Without<...> & AccountUncheckedUpdateManyInput) | (Without<...> & AccountUpdateManyMutationInput)>'
Object literal may only specify known properties, and 'pull' does not exist in type 'string[] | AccountUpdateguildIdsInput | { set?: Exact<string[] | undefined, string[] | undefined>; push?: Exact<string | string[] | undefined, string | string[] | undefined>; }'.ts(2353)
index.d.ts(4604, 5): The expected type comes from property 'guildIds' which is declared here on type 'Exact<(Without<AccountUpdateManyMutationInput, AccountUncheckedUpdateManyInput> & AccountUncheckedUpdateManyInput) | (Without<...> & AccountUpdateManyMutationInput), (Without<...> & AccountUncheckedUpdateManyInput) | (Without<...> & AccountUpdateManyMutationInput)>'
Which is weird because pull is a documented update operator under MongoDB here: https://www.prisma.io/dataguide/mongodb/managing-documents Also, my schema states guildIds as string[]. So indeed it is an array, and indeed guild_id is a string. Thanks!
5 Replies
jonfanz
jonfanz10mo ago
I think it’s supposed to be $pull instead of pull?
Zeke
ZekeOP10mo ago
Same error. That doesn't exist. Why would push not be $push if pull were supposed to be $pull too?
jonfanz
jonfanz10mo ago
Oh! I'm sorry, I really messed up. Those commands (and the dataguide as a whole) are for their respective DB. The examples aren't using Prisma ORM, they're examples inside of the Mongo shell. You can see similar examples in MongoDB's docs here: https://www.mongodb.com/docs/manual/reference/operator/update/pull/
jonfanz
jonfanz10mo ago
For Prisma ORM + MongoDB docs, this page is your best bet: https://www.prisma.io/docs/orm/overview/databases/mongodb
Prisma
MongoDB database connector
How Prisma can connect to a MongoDB database using the MongoDB database connector.
Zeke
ZekeOP10mo ago
Hm. Doesn't look like pull even exists. The only fix I can think of is finding the document, grabbing guildIds, then updating guildIds to be the pre-found array filtering out guild_id. But that seems too complex for the task at hand. Surely, a method exists somewhere? Thanks nonetheless. Ended up removing my string array and replacing it with an ‘AccountGuild’ model array. This way I can target each one individually.
Want results from more Discord servers?
Add your server