Today, we are excited to share the `3.11.0` stable release 🎉
🌟 **Help us spread the word about Prisma by starring the repo or [tweeting](https://twitter.com/intent/tweet?text=Check%20out%20the%20latest%20prisma%20release%20v3.11.0%20%F0%9F%9A%80%0D%0A%0D%0Ahttps://github.com/prisma/prisma/releases/tag/3.11.0) about the release.** 🌟
Major improvements and new features
Experimental support for Embedded Document Filters
In the previous release, we added embedded document support for creates, updates, and deletes. In version `3.11.0`, we’re adding the ability to filter embedded documents.
Given the following schema:
prisma
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["mongoDb"]
}
model Product {
id String id default(auto()) map("_id") db.ObjectId
photos Photo[]
}
model Order {
id String id default(auto()) map("_id") db.ObjectId
shippingAddress Address
billingAddress Address?
}
type Photo {
height Int
width Int
url String
}
type Address {
street String
city String
zip String
}
You can now filter within an embedded document:
ts
// find all orders with the same shipping address
const orders = await prisma.order.findMany({
where: {
shippingAddress: {
equals: {
street: "555 Candy Cane Lane",
city: "Wonderland",
zip: "52337",
},
},
},
})
You can also filter on a "contains many" relationship:
ts
// find all products that don't have photos
const product = prisma.product.findMany({
where: {
photos: {
isEmpty: true
}
},
})
This scratches the surface of what's possible. For a complete list of available operations, have a look at [our documentation](https://www.prisma.io/docs/concepts/components/prisma-client/composite-types). Please share your feedback in [this issue](https://github.com/prisma/prisma/issues/8241).
Ordering by embedded documents is in Preview
In addition to filtering, Prisma version `3.11.0` now supports sorting by an embedded document.
Using the example schema above, you can sort orders by their zip code:
ts
// sort orders by zip code in ascending order
const orders = await prisma.order.findMany({
orderBy: {
shippingAddress: {
zip: "asc",
},
},
})
Learn more about this feature in [our documentation](https://www.prisma.io/docs/concepts/components/prisma-client/composite-types) and don’t hesitate to reach out in [this issue](https://github.com/prisma/prisma/issues/8241).
MongoDB query logging support
In this release, we’ve added the ability to log MongoDB queries. You can enable query logging in the `PrismaClient` constructor:
ts
const prisma = new PrismaClient({
log: [
{
emit: 'event',
level: 'query',
},
]
})
prisma.$on('query', (e) => console.log(e.query))
After enabling query logging, you'll start to see logs that resemble this in your console:
bash
db.User.deleteMany({ _id: ( $in: [ “62261e0b18139c6099ba7097”, ], }, })
db.User.deleteMany({ _id: ( $in: [ “6226277a96069500743edcf9”, ], }, })
The logs output by Prisma have the same format as the `mongosh` console, so you can pipe the queries from your logs directly into your shell.
MongoDB introspection update
We've updated the type inference behavior for MongoDB on introspection.
Prisma samples a field's data to select an appropriate type on introspection. In the past, Prisma picked the type used most often for fields with data with multiple types. However, this could cause problems when retrieving mixed data during runtime and throw exceptions, such as Prisma Studio or in Prisma Client queries.
From `3.11.0`, Prisma defaults to the `Json` type to all fields with mixed data types instead. Additionally, Prisma will still show a warning on the console and add a comment to the introspected Prisma schema so it is clear where such cases occur and that you can do something to fix them.
Prisma Client logger revamp
In `3.11.0`, we’ve rewritten our internal logger to reduce [lock contention](https://en.wikipedia.org/wiki/Lock_(computer_science)#:~:text=lock%20contention%3A%20this%20occurs%20whenever,lock%20held%20by%20the%20other.) and enable future features like tracing. This is the first of many upcoming changes to improve the Prisma Client’s throughput, so if you were running into an upper limit on query performance, it’s time to update Prisma Client and give it a try!
If you're running into query performance issues, please [open an issue](https://github.com/prisma/prisma/issues/new/choose) or [connect with us on Slack](https://slack.prisma.io/).
CockroachDB now supports migrations (Preview)
We're excited to announce Preview support for migrations for CockroachDB. You can now evolve your Prisma schema and propagate the changes to your database using Prisma Migrate.
Give the feature a try and let us know what you think in [this issue](https://github.com/prisma/prisma/issues/11542).
Detecting state of a diff with `migrate diff` using exit code
Prisma version `3.11.0` includes a new `--exit-code` flag to the `migrate diff` command to detect the state of a diff in several ways.
You can use the flag as follows:
bash
npx prisma migrate diff --preview-feature \
--exit-code \
--from-[...] \
--to-[...]
Here's a list of the default and changed behavior of the error codes:
Default behavior of exit codes
0: Returned when the diff is empty or non-empty
1: Returned on error
Changed behavior when --exit-code is used
0: Returned when the diff is empty
1: Returned on error
2: Returned when the diff is non-empty
Read about it in the [reference documentation](https://www.prisma.io/docs/reference/api-reference/command-reference#migrate-diff).
Fixes and improvements
Prisma
- [Command to export SQL schema](https://github.com/prisma/prisma/issues/1992)
- [Waiting "too long" to input migration name leads to error message](https://github.com/prisma/prisma/issues/7742)
- [`db push` with empty `schema.prisma`: `Error: TypeError: Cannot read properties of undefined (reading 'url')`](https://github.com/prisma/prisma/issues/9518)
- [migrate diff: --{from,to}-schema-datamodel should not error on missing env vars in datasource blocks ](https://github.com/prisma/prisma/issues/11544)
- [migrate diff: Provide a reliable way to detect empty diffs / migrations](https://github.com/prisma/prisma/issues/11566)
- [`db execute` cannot resolve SQLite file path from schema](https://github.com/prisma/prisma/issues/11626)
- [[MDB] Implement version and describe RPC calls for the error reporting backend](https://github.com/prisma/prisma/issues/11691)
- [[MDB] Create fields referenced in index definitions as Json to enable display of indexes in datamodel ](https://github.com/prisma/prisma/issues/11933)
- [MongoDB many to many: `PANIC: called Option::unwrap() on a None`](https://github.com/prisma/prisma/issues/11970)
Prisma Client
- [PANIC in query-engine/connectors/mongodb-query-connector/src/value.rs:185:24not yet implemented: (Json, Json("[]"))](https://github.com/prisma/prisma/issues/6773)
- [Prisma Mongo Panic called `Option::unwrap()` on a `None` value](https://github.com/prisma/prisma/issues/8598)
- [Better error message for MongoDB replica sets](https://github.com/prisma/prisma/issues/8719)
- [MongoDB: Using `tlsCAFile` fails](https://github.com/prisma/prisma/issues/9072)
- [no such file or directory, open '/path/schema.prisma' since 3.1.1](https://github.com/prisma/prisma/issues/9435)
- [PANIC: called `Option::unwrap()` on a `None` value in query-engine/connectors/mongodb-query-connector/src/root_queries/write.rs:301:74](https://github.com/prisma/prisma/issues/9977)
- [`contains` string filter not working with mongoDB](https://github.com/prisma/prisma/issues/10267)
- [Referential integrity is not preserved when updating foreign key (in "prisma" mode)](https://github.com/prisma/prisma/issues/11100)
- [PANIC: called `Option::unwrap()` on a `None` value in query-engine\connectors\mongodb-query-connector\src\root_queries\read.rs:112:74](https://github.com/prisma/prisma/issues/11378)
- [HasReject not evaluating correctly for per operation handlers](https://github.com/prisma/prisma/issues/11403)
- [Support MongoDB "query" logging](https://github.com/prisma/prisma/issues/11419)
- [CONTRIBUTING: document Prisma Client workflow of using local link ](https://github.com/prisma/prisma/issues/11828)
- [MongoDB findRaw filter problem with ObjectId field.](https://github.com/prisma/prisma/issues/11830)
- [MongoDB: Better error message for when document does not match the defined schema](https://github.com/prisma/prisma/issues/11853)
- [Integrate orderBy for composite types](https://github.com/prisma/prisma/issues/12038)
- [Attempting to do a query in the Prisma Client on a model with a foreign key that has `map` panics on 3.10.0](https://github.com/prisma/prisma/issues/12105)
- [Use embedded documents attributes in where clause](https://github.com/prisma/prisma/issues/12186)
- [`'then' in PrimsaPromise` returns false](https://github.com/prisma/prisma/issues/12252)
Prisma Migrate
- [Detect schema drift helper / `migrate dev --exit-code`](https://github.com/prisma/prisma/issues/9707)
- [Migrate lock timeout on PlanetScale](https://github.com/prisma/prisma/issues/10997)
Language tools (e.g. VS Code)
- [MongoDB M:N relations get referential actions auto completion suggestions, then does not validate](https://github.com/prisma/language-tools/issues/1060)
- [Auto Completion: `map` does not exist for M:N in MongoDB](https://github.com/prisma/language-tools/issues/1061)
- [Autocomplete shows invalid suggestions for composite types](https://github.com/prisma/language-tools/issues/1063)
- [Suggest auto() in VSCode autocomplete](https://github.com/prisma/language-tools/issues/1064)
- [Clicking on a MongoDB composite type does not jump to definition](https://github.com/prisma/language-tools/issues/1069)
Prisma Engines
- [Implement order by composites](https://github.com/prisma/prisma-engines/issues/2514)
- [[Composites] Implement `equals` read operation](https://github.com/prisma/prisma-engines/issues/2675)
- [[Composites] Implement `is` read operation](https://github.com/prisma/prisma-engines/issues/2676)
- [[Composites] Implement `isNot` read operation](https://github.com/prisma/prisma-engines/issues/2677)
- [[Composites] Implement `isEmpty` read operation](https://github.com/prisma/prisma-engines/issues/2678)
- [[Composites] Implement `every` read operation](https://github.com/prisma/prisma-engines/issues/2679)
- [[Composites] Implement `some` read operation](https://github.com/prisma/prisma-engines/issues/2680)
- [[Composites] Implement `none` read operation](https://github.com/prisma/prisma-engines/issues/2681)
Credits
Huge thanks to hayes, maddhruv, jasimon for helping!
📺 Join us for another "What's new in Prisma" livestream
Learn about the latest release and other news from the Prisma community by joining us for another ["What's new in Prisma"](https://youtu.be/2dAtmHuT-30) livestream.
The stream takes place [on YouTube](https://youtu.be/2dAtmHuT-30) on **Thursday, March 17** at **5 pm Berlin | 8 am San Francisco**.