PinkiePie
06/28/2022, 5:46 AMbulkWrite
with $runCommandRaw
?millsp
06/28/2022, 5:23 PM$transaction([...])
?PinkiePie
06/28/2022, 8:26 PM$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({...}) }
aggregate, updateMany, aggregate
, so for 100 of items it's 300 sequential requestsnikolasburk
07/12/2022, 8:15 AMPinkiePie
07/13/2022, 8:59 AMbulkWrite
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 librariesnikolasburk
07/13/2022, 9:06 AMdocs
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 🙏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?PinkiePie
07/15/2022, 7:34 AM$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 purposenikolasburk
07/15/2022, 7:54 AMPinkiePie
07/15/2022, 8:24 AM$runCommandRaw
, so it was not necessary to create another one