nikolasburk
prisma db pull
against a MongoDB database with existing data will sample the data and create a Prisma data model based on the stored documents.
This comes with a few caveats:
• The preview feature mongoDb
must be enabled on the datasource
block in the Prisma schema.
• The MongoDB instance must have at least one collection with at least one document.
• To introspect indices, there must be at least one document in the collection with the indexed fields.
• If any fields have conflicting types, the most common type is chosen and the other types are written to a comment above the field in the Prisma schema.
• Relations must be added manually after introspection.
• Running prisma db pull
multiple times will overwrite any added text in the data model for now.
We're constantly iterating on this feature, so please provide feedback for introspecting MongoDB databases!
🔢 Get the count of a relation in MongoDB
This release, we're giving MongoDB developers the ability to query the count of a relation. In the example below, we're getting the number of posts each user wrote:
const userWithPostsCount = await prisma.user.findMany({
include: {
_count: {
select: { posts: true },
},
},
})
// => [
// {
// email: "<mailto:alice@prisma.io|alice@prisma.io>",
// _count: { posts: 3 }
// }
// ]
This feature was previously available for SQL databases and now it's also available in MongoDB. Learn more in our 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 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, my colleague @Daniel Norman and I will discuss the latest release and other news from the Prisma ecosystem in a on Thursday at 5pm Berlin | 8am San Francisco.