Alex Ruheni
3.11.0
prisma rainbow
📦 Experimental support for embedded document filters (MongoDB)
In the previous release, we added embedded document support for creates, updates, and deletes. In version 3.11.0
, we’re adding experimental support for filtering embedded documents. Given the following schema:
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? /// optionally embedded document
}
type Photo {
height Int
width Int
url String
}
type Address {
street String
city String
zip String
}
You can now add filters within an embedded document:
// find all orders with the same shipping address
const orders = await prisma.order.findMany({
where: {
shipping: {
equals: {
street: "555 Candy Cane Lane",
city: "Wonderland",
zip: "52337",
},
},
},
})
You can also add a filter on a “contains many” relationship:
// 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. Please share your feedback in this issue.
🗃️ Ordering by embedded documents is in Preview (MongoDB)
In addition to filtering, version 3.11.0
now supports sorting by by an embedded document. Using the example schema above, you can sort orders by their zip code:
// 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, and don’t hesitate to reach out in this issue.
🪵 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:
const prisma = new PrismaClient({
log: [
{
emit: 'event',
level: 'query',
},
]
})
prisma.$on('query', (e) => console.log(e.query))
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. On introspection, Prisma samples the data of a field to find an appropriate type.
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 throwing 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. Additionally, Prisma still shows a warning on the console and adds 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 and enable future features like tracing. If you’re running into query performance issues, please open an issue.
🦦 CockroachDB now supports migrations (Preview)
We’re excited to announce Preview support for migrations for CockroachDB. Give it a try and let us know what you think in this issue.
🔍 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
to detect the state of a diff. Please read about it in the reference documentation.
📚 Learn more in the release notes
For more info and links to documentation, you can read the release notes.
🌟 Help us spread the word about Prisma. 🌟
To help spread the word about Prisma, we’d very much appreciate it if you would star the repo 🌟 And if you’re excited about the features in this week’s release, then help us and share your excitement on Twitter.
📰 Join us on Thursday for the “What’s new in Prisma” livestream
This week, @Austin and I will discuss the latest release and other news from the Prisma ecosystem in a this Thursday at 5 pm Berlin | 9 am San Francisco.