How to query on JSON field type with an object that contains at least the properties stored in the database #24004
Replies: 2 comments
-
Hi @mhmdsalahsebai 👋 Prisma Client does not support partial matching or ignoring additional properties in the JSON field. The JSON field in the query must exactly match the JSON field in the database. For Example: const getEvents = await prisma.event.findMany({
where: {
additionalFields: {
path: ['name'],
equals: 'This is a name',
},
},
}) The query returns all events where the However, you can open a feature request and document your usecase so our engineers can take a look. |
Beta Was this translation helpful? Give feedback.
-
Hi @ludralph, Thanks for your response. Do you know if this is possible with raw SQL? I searched a lot and I didn't find anything thanks. |
Beta Was this translation helpful? Give feedback.
-
Question
I have a Prisma model defining events stored in a PostgreSQL database. One of the fields is additionalFields, which is a JSON object. How can I construct a Prisma query to retrieve events, matching even if the additionalFields contain additional properties beyond those specified in the query? Here's my model:
Suppose I have an event in the database with the following data:
I want to construct a Prisma query that can match this event even if the additionalFields contain extra properties. For instance, the query below should match the event above:
but this should not match,since there is a missing property:
How to reproduce (optional)
Expected behavior (optional)
No response
Information about Prisma Schema, Client Queries and Environment (optional)
// Add your schema.prisma
// Add any relevant Prisma Client queries here
OS:
Database:
Node.js version:
Run
prisma -v
to see your Prisma version and paste itBeta Was this translation helpful? Give feedback.
All reactions