Not able to determine why I am getting an invalid_null_access error. V10 question

Hello,

I have this query, and I am not sure what the error is. Ther is some value missing in the data, but not sure what it is.

Users.all().map(user_doc => “#{User_sessions.all().where(.userRef.data.first() == user_doc.id).count()} #{user_doc.email} #{Plants.all().where(.userId == user_doc.googleID).count()} #{Plants.all().where(.userId == user_doc.googleID).map(plant_doc => Plant_tasks.all().where(.value.plantId == plant_doc.id).count()).toSet().toArray().aggregate(0,(a,b) => a + b)}”).paginate(2)

Error is shown in the attached image. Is the error that there are plant_task documents where the plantId does not exist in the Plants collection?

I wish the error log was more descriptive of the error. Since there is no good UI for seeing the data, I am stuck as to why i am getting this error. The query works; just this dataset is missing something.

Your query is very wide, but the if you were able to see the error without line wrapping, then I believe you should see the error highlighted under .value.plantid.

The error states Cannot access `plantId` on null

You are only trying to access plantId on the value property for some Plant_tasks documents. So it is most likely that some of your Plant_tasks documents do not have a value property. When you access a field that does not exist it resolves to null, so when you execute .value it results in null when the field does not exist (Fauna does not store explicit null values).

Got it! Thanks @ptpaterson ! The docs where there was value field, were throwing the error. I used this query to quickly update them: Plant_tasks.all().where(.value == null).toSet().toArray().map(doc => doc.update({value:{}}))

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.