Geebrox
08/15/2022, 2:29 PMInvalid `prisma.user.upsert()` invocation:
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: RawDatabaseError { code: "unknown", message: "Command failed (WriteConflict): WriteConflict error: this operation conflicted with another operation. Please retry your operation or multi-document transaction.)" } })
What does it mean?Nurul
08/16/2022, 9:18 AMGeebrox
08/16/2022, 1:53 PMNurul
08/18/2022, 7:13 AMGeebrox
08/18/2022, 7:16 AMNurul
08/18/2022, 7:52 AM// This is your Prisma schema file,
// learn more about it in the docs: <https://pris.ly/d/prisma-schema>
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
model Images {
imageID String @id @default(auto()) @map("_id") @db.ObjectId
messageID String?
userID String?
guild String?
channelID String?
logID String?
url String
type String
interactionType String?
isVideo Boolean?
tags String[]
likedBy Users[] @relation(fields: [likedByIds], references: [id])
likedByIds String[] @db.ObjectId
}
model Users {
id String @id @default(auto()) @map("_id") @db.ObjectId
premium Boolean @default(false)
tagsSuggested Int @default(0)
baraRequested Int @default(0)
isContribuitor Boolean @default(false)
liked Images[] @relation(fields: [likedImageIds], references: [imageID])
likedImageIds String[] @db.ObjectId
}
index.ts
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient({
log: ['query'],
});
async function main() {
const user = await prisma.$transaction([
prisma.users.upsert({
where: {
id: '62fdeed1fd3ad81be5088625',
},
create: {
baraRequested: 1,
isContribuitor: true,
},
update: {
baraRequested: 0,
},
}),
]);
console.log(user);
}
main()
.catch((e) => {
throw e;
})
.finally(async () => {
await prisma.$disconnect();
});
output:
> ts-node index.ts
prisma:query db.Users.aggregate([ { $match: { $expr: { $and: [ { $and: [ { $eq: [ "$_id", ObjectId("62fdeed1fd3ad81be5088625"), ], }, { $or: [ { $ne: [ { $ifNull: [ "$_id", null, ], }, null, ], }, { $eq: [ "$_id", null, ], }, ], }, ], }, ], }, }, }, { $project: { _id: 1, }, }, ])
prisma:query db.Users.insertOne({ premium: false, tagsSuggested: 0, baraRequested: 1, isContribuitor: true, })
prisma:query db.Users.aggregate([ { $match: { $expr: { $and: [ { $and: [ { $eq: [ "$_id", ObjectId("62fdef31bb9d6b0c1dc90110"), ], }, { $or: [ { $ne: [ { $ifNull: [ "$_id", null, ], }, null, ], }, { $eq: [ "$_id", null, ], }, ], }, ], }, ], }, }, }, { $project: { _id: 1, premium: 1, tagsSuggested: 1, baraRequested: 1, isContribuitor: 1, likedImageIds: 1, }, }, ])
[
{
id: '62fdef31bb9d6b0c1dc90110',
premium: false,
tagsSuggested: 0,
baraRequested: 1,
isContribuitor: true,
likedImageIds: []
}
]
Geebrox
08/20/2022, 12:14 PMRichard
09/18/2022, 7:50 AMupdateMany
call.
Is this related to this open Prisma issue?Richard
09/18/2022, 7:58 AMupdateMany
to the $transaction
doesn't work 😞
async updateMany(data: IToken) {
// updateMany threw following error:
// WriteConflict error: this operation conflicted with another operation. Please retry your operation or multi-document transaction.
return await this.prisma.$transaction([
this.prisma.token.update({
where: { userId: data.userId },
data: {
...(data.accessToken && { accessToken: data.accessToken }),
...(data.refreshToken && { refreshToken: data.refreshToken }),
},
}),
]);
}
Richard
09/18/2022, 7:59 AMError:
Invalid `this.prisma.token.update()` invocation in
/Users/richardpoelderl/backend/src/auth/auth.repository.ts:22:25
19 // updateMany threw following error:
20 // WriteConflict error: this operation conflicted with another operation. Please retry your operation or multi-document transaction.
21 return await this.prisma.$transaction([
→ 22 this.prisma.token.update(
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: RawDatabaseError { code: "unknown", message: "Command failed (WriteConflict): WriteConflict error: this operation conflicted with another operation. Please retry your operation or multi-document transaction.)" } })
Geebrox
09/18/2022, 7:59 AMRichard
09/18/2022, 8:01 AMRichard
09/18/2022, 8:02 AMGeebrox
09/18/2022, 8:07 AMRichard
09/18/2022, 8:16 AMRichard
09/18/2022, 8:17 AMRichard
09/18/2022, 8:17 AMRichard
09/18/2022, 8:53 AMRichard
09/18/2022, 8:54 AMRichard
09/18/2022, 8:55 AM