New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MongoDB views cause db push error #18424
Comments
Migrations, which includes |
Thanks for your response @janpio, but I'm not trying to add an index to the view, but another model. Adding that index, after removing the view from the DB, is actually working. To be clear, I'm not trying to migrate or push a view. But there being a view in the DB causes this issue. |
Can you share an example schema that does not work, the commands required to setup the database behind it, and then a schema that does work with the same database? Thanks. |
The schema doesn't affect the error. The fact that a view is available in the database is enough to cause an issue. Schema: generator client {
provider = "prisma-client-js"
previewFeatures = ["views"]
}
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
@@map("users")
} Doing a To have the error occur, add a view. For example, use a seed script with the following: await prisma.$runCommandRaw({
create: 'userView',
viewOn: 'users',
pipeline: [
{
$addFields: {
foo: "bar"
}
},
]
}); Trying to run |
The solution is probably somewhere in simply ignoring views when looping over collections. The MongoDB differ is trying to collect indexes for all collections, but views do not have indexes: See MongoDB documentation: I'm not a Rust developer, else I would have created a PR for it. Thanks for looking into it! |
2 months in and I wonder if this is being looked at. It's as simple as filtering only the collections and ignoring the views, like in this Stack Overflow issue: https://stackoverflow.com/questions/56013171/mongodb-list-collection-without-showing-views |
Looks like a duplicate of #16179 |
Also related: #17006 |
Any news on this? Having the same issue over here. @jamiter, could you let me know if you found a workaround? |
@christianledgard, we currently remove the views before doing the db push. Our seed script ads them again afterwards. This is done automatically in our setup. In concept it works like this: npm run db:remove-views
npm run db:push
npm run db:seed /* adds views again */ Because the views do not contain any data directly this is not an issue. The big downside (besides being a workaround) is that the views do not exist for roughly 10 seconds, which could be an issue on production. And because we want to always be able to release, I hope this will be fixed soon. It doesn't seem like a lot of work to fix... I tried it myself but didn't get the engines build correctly with rust on my M1. |
Note: This is now fixed in |
Prisma version: 4.11.0
Provider: MongoDB
I'm trying to set my MongoDB indexes (for
@unique
for example) using thedb push
command. I've added a MongoDB view to the database which causes this error:Removing the view from the database makes
db push
run successfully, setting the desired indexes.Reproduction:
prisma db push
Reported this issue in this ticket earlier: #678 (comment)
Edit: It might be good to mention that this error also shows up when doing a
prisma db pull --force
when there is a view in the database.The text was updated successfully, but these errors were encountered: