Prisma with CosmosDB, MongoDB connector has error for sharded collections
See original GitHub issueDiscussed in https://github.com/prisma/prisma/discussions/9544
<div type='discussions-op-text'>Originally posted by dohaicuong October 1, 2021 Hi Prisma Team! I just got this error when setup Prisma with MongoDB on Azure CosmosDB and create a sharded collection
Invalid `prisma.user.create()` invocation:\n\n\n Error occurred during query execution:\nConnectorError(ConnectorError {
user_facing_error: None, kind: RawError {
code: \"unknown\", message: \"Command failed (50841): Multi-document transactions cannot be run in a sharded collection)\"
} })
Versions
- Node: v14.17.4
- OS: macOs
- Prisma client: 3.1.1
- Database: MongoDB 4.0 on Azure CosmosDB
Schema
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["mongoDb"]
}
model User {
id String @id @default(dbgenerated()) @map("_id") @db.ObjectId
name String
}
MongoDB setup
- Create mongoDB 4.0 on cosmosDB
- Create new DB and User collection with shard key
Connection string
mongodb://user:pass@url/db_name?ssl=true
&connectTimeoutMS=5000
&maxPoolSize=50
&replicaSet=globaldb
&retrywrites=false
&maxIdleTimeMS=120000
&appName=@app_name@
Prisma command
const newUser = await prisma.user.create({
data: { name: 'name' }
})
Errors
Invalid `prisma.user.create()` invocation:\n\n\n Error occurred during query execution:\nConnectorError(ConnectorError { user_facing_error: None, kind: RawError { code: \"unknown\", message: \"Command failed (50841): Multi-document transactions cannot be run in a sharded collection)\" } })
```</div>
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Troubleshoot common errors in Azure Cosmos DB's API for ...
Code Error Description
13 Unauthorized The request lacks the permissions to complete.
67 CannotCreateIndex The request to create an index can't be completed.
115 CommandNotSupported The...
Read more >MongoDB database connector - Prisma
The MongoDB data source connector connects Prisma to a hosted MongoDB instance ... has no replica set configured, you can experience an error...
Read more >Azure Cosmos DB Pitch Deck L400 - WinDays.hr
Azure Cosmos DB uz MongoDB API i SQL API. Ivan Pranjić. Blink d.o.o. ... Cons: Fixed schemas help prevent errors ... The unit...
Read more >expected connection string to start with mongodb:/ or mongodb+srv ...
Describe the bug When trying to use Strapi with the mongoose connector and Azure CosmosDB (MongoDB API 3.6), Strapi crashes with an error....
Read more >Error in connector: missing field `info` - Prisma Introspection ...
I have created an Express, Apollo GraphQL server which accepts requests and returns data from a MongoDB database via Prisma.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Unfortunately the MongoDB API of Azure CosmosDB is stuck at version 4.0: https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb/mongodb-introduction#how-the-api-works @matthewmueller - but this problem is CosmosDB specific, not caused by MongoDB 4.0 (see below)
I can now also reproduce a close error with a simple CosmosDB with MongoDB 4.0 API via the CosmosDB Emulator:
Knowing these concepts now, I could also find the documention on the CosmosDB side for this:
https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb/feature-support-40#transactions
So:
The exact error you got @dohaicuong I indeed only get when I create a collection via the web UI and explicitly enable sharing on it:
I assume that is also what you did?
Side note: We also do not know yet if we support Shard Clusters of normal MongoDB: https://github.com/prisma/prisma/issues/12380