Title
p

PinkiePie

06/28/2022, 5:46 AM
can i somehow use
bulkWrite
with
$runCommandRaw
?
👀 1
@millsp hi, maybe you know something about this?
m

millsp

06/28/2022, 5:23 PM
Hey, are you unable to get this working with
$transaction([...])
?
p

PinkiePie

06/28/2022, 8:26 PM
nope,
$transaction([...])
doesn't batch anything, but instead, it runs a bunch of separate requests sequentially. even worse, after updating each item it runs
aggregate
and I have no way to prevent it. So, if I need to update 3 items at once, Prisma would generate 6 sequential requests to the database, where network latency would slow down everything a lot. These 6 requests would be
updateMany, aggregate, updateMany, aggregate, updateMany, aggregate
. Why would it be an
updateMany
for every single item is a separate question 😄 And I would have about 100 of items to update at once, so Prisma would generate 200 sequential requests, with 10ms latency from my server to the DB it would take 2 seconds at best. And if I'd run
bulkWrite
it would take ~20ms for the entire operation. So
$transaction([...])
here is not even a workaround, for batching, it's just a wrapper for
for (const article of articles) { await prisma.article.update({...}) }
ah, it's even worse, it's 3 requests per item:
aggregate, updateMany, aggregate
, so for 100 of items it's 300 sequential requests
n

nikolasburk

07/12/2022, 8:15 AM
Hey @PinkiePie 👋 would you mind opening a GitHub issue about this so that our Engineers can look into it properly? 🙂
p

PinkiePie

07/13/2022, 8:59 AM
@nikolasburk but the issue above is not that relevant to my original question 🙂 I'd like to run
bulkWrite
with
$runCommandRaw
. Even if
$transaction
would work properly, I don't need a result of the operation. I just want to update a bunch of documents at once, with as low an impact on DB as possible. So that's a question about documenting
$runCommandRaw
, because for now, I have to stick to the native driver (https://github.com/mongodb/node-mongodb-native) alongside with Prisma for such kind of requests. With relational DBs I can run any SQL code I want using Prisma, but with Mongo, I have to use 3rd party libraries
n

nikolasburk

07/13/2022, 9:06 AM
Ah I see, thanks for the clarification! In that case, could you create an issue in the
docs
repo. We definitely have some deficits in the docs for
$runCommandRaw
, so any additional use cases that are persisted in issues would be really helpful here 🙏
Could you also elaborate a bit on what exactly you’re missing from the docs here? https://www.prisma.io/docs/concepts/components/prisma-client/raw-database-access#runcommandraw Do you just want to see an example of
bulkWrite
being used with
$runCommandRaw
or are there any other specifics about
bulkWrite
that make this part of the docs unhelpful for your use case?
p

PinkiePie

07/15/2022, 7:34 AM
I'd say we need any kind of documentation because the current one is nearly useless. There are multiple issues already exists: https://github.com/prisma/docs/issues/3220 https://github.com/prisma/docs/issues/3209
@nikolasburk what kind of input
$runCommandRaw
accept? no idea. the issue above says that it's from here: https://www.mongodb.com/docs/manual/reference/command/ ok then, I've run the command in the mongo shell and it works, but the same command in Prisma doesn't. did Prisma modify my input? no idea, because Prisma doesn't log the
$runCommandRaw
query. Maybe it's because I use ObjectID for the query? how can I tell Prisma that my
_id
is an
ObjectID
? no idea, because in the example here https://www.prisma.io/docs/concepts/components/prisma-client/raw-database-access#runcommandraw there is just a useless number instead of ObjectID which nobody uses for the real apps. Maybe I can just pass my data as a string, because
db.runCommand
should accept the string, so I can manually wrap my _id into
ObjectId()
? maybe, but Prisma does not allow to pass the string to
$runCommandRaw
and I can't do that. (or maybe it somehow can? you can't tell it from the docs, at least TS types are incompatible with string). So you see how much stuff we need to dig into and debug just to run a simple command, that we already tested in the shell? I already spent a few hours on it without any success, I still have to use mongo native driver for that purpose
n

nikolasburk

07/15/2022, 7:54 AM
That’s great info, thanks a lot! I’ll share that with the team to hopefully get the docs updated soon 🙏
We’ve also recorded all of your feedback in a new issue now! https://github.com/prisma/docs/issues/3423
💯 1
p

PinkiePie

07/15/2022, 8:24 AM
thx a lot! I thought that we have a few issues related to the
$runCommandRaw
, so it was not necessary to create another one
👍 1