If i use any scalar JSON type, throws not implemented error
Describe the bug An error was thrown while querying a document with JSON scalar type on MongoDB.
{"exception":"java.lang.RuntimeException: Not implemented: com.prisma.shared.models.TypeIdentifier$Json$@42bb724d{ "coordinates" : [-74.063644, 4.624335], "type" : "Point" }
To Reproduce Steps to reproduce the behavior:
- Create a scalar type JSON
- Fill it with some object
- Query that document.
- Error is thrown
Expected behavior A query with the entire document.
Screenshots If applicable, add screenshots to help explain your problem.
Versions (please complete the following information):
- Connector:
MongoDB - Prisma Server:
1.28.3 prismaCLI: prisma/1.28.5 (darwin-x64) node-v10.15.1- OS:
Ubuntu 18.04.1 LTS - other dependencies:
docker 18.06.1-ce
Additional context
I am trying to use a GeoJson object, so I am using Mongoose for the User document creation.
Hey @epileftro85 ,
when you create a JSON field using Prisma you have to provide the JSON in stringified form at the moment. For historical reasons (since we started out with SQL databases) we then store this in a String column in the database. When reading a JSON field Prisma therefore expects the underlying database column/field to be of type String and contain a stringified JSON.
Mongoose is probably storing the JSON as BsonDocument or BSONArray. Prisma cannot read that at the moment which is why you are getting this error.
There are two possible solutions until we rework the way Prisma stores JSON on all connectors.
- You keep the datamodel-field as type JSON and accept that Prisma stores/reads it as stringified Json in a BSONString field, then Mongoose or other applications that write to these documents would also need to adhere to that convention.
- You change the datamodel-field to a relation to an embedded type. Then Prisma will create a nested structure of the shape of the embedded type that might work naturally with other applications like Mongoose. This is of course only an option if the shape of your expected JSONs is fairly uniform which for you seems to be the case.
type Location @embedded{
coordinates: [Float]
type: String # could also be an Enum
}
I hope that helps.
Hi @do4gr, I've already done the second option, for some reason MongoDB didn't query location on such embedded object, I think it is because the embedded option generates an internal id and the GeoJson doesn't support that structure.
For the first option, I prefer to keep using the GeoJson field for MongoDB because Mongoose can query that field.
Thank you for your time, I will keep combining mongoose for somethings that Prisma is not ready for.