MichaelSolati / geofirestore-js

Location-based querying and filtering using Firebase Firestore.
https://geofirestore.com
MIT License
505 stars 58 forks source link

DocumentReference.set() called with invalid data. Unsupported field value: a custom object #169

Closed amitkalo closed 4 years ago

amitkalo commented 4 years ago

hii all im using geofirestore and in my usege i try to add new document to my DB. i do it as mention in the examples with the add functonality and in the data object i want to add an array with pointer to other documents that i insert with firestore.

await geocollection.add({ coordinates: new firebase.firestore.GeoPoint(latlng.lat, latlng.lng), refArray: [newRef] })); on this line i get the following error: { FirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: a custom object (found in field d.refArray)

i try to use Object.asset({}, newRef) but its put an empty array. please help

MichaelSolati commented 4 years ago

Ah, just saw this on StackOverflow, but here's what I posted there:


So in a lot of cases geofirestore minimally modifies the doc you give and then passes it through to Firestore. In this case it looks like Firebase/Firestore is throwing the error, not geofirestore.

I suspect that the issue is with the reference you're using. If that reference is provided by geofirestore, it's not necessarily a DocumentReference that Firestore uses, it is a GeoDocumentReference. You'll likely want to get the actual DocumentReference from the native property:

await geocollection.add({
  coordinates: new firebase.firestore.GeoPoint(latlng.lat, latlng.lng),
  arrayOfRef: [newRef.native]
});

Let me know if that helps! I'm also making a few assumptions as to your code, so seeing more of what happens before you call the add method would be awesome.

amitkalo commented 4 years ago

its not worked since the newRef is not a GeoDocumentReference as you can see, the newRef is returning from insertNewRef which using firestore-admin to insert new document and return the DocumentReference of it:

await GeoLocationDB.get().then(async function(querySnapshot){ await insertNewRef().then(async function(newRef){ if (querySnapshot.size == 0){ await geocollection.add({ coordinates: new firebase.firestore.GeoPoint(latlng.lat, latlng.lng), posts: [newRef] });

MichaelSolati commented 4 years ago

Ok, so I attempted to implement something you're doing in a StackBlitz (I'm using the web client, not the server).

Here's the blitz, and it seems to work just fine. However I noticed an issue with Firestore where if the coordinates are [0, 0] it throws an issue (I'm gonna pass this issue to the Firebase team firebase/firebase-js-sdk#3006)

https://stackblitz.com/edit/geofirestore-169?file=index.ts

amitkalo commented 4 years ago

Great, thanks and i will glad if you will update😊

amitkalo commented 4 years ago

@MichaelSolati why did you close it? its not resolved yet

MichaelSolati commented 4 years ago

Sorry, I didn't hear back from you so I supposed we were good. I'll reopen it now.

MichaelSolati commented 4 years ago

@amitkalo did you get to try the code example I wrote?

amitkalo commented 4 years ago

yes, you can see my answer to your suggest in the older comments here

MichaelSolati commented 4 years ago

@amitkalo I'm sorry I dont see any updates you've shared based on my StackBlitz. Could you repost it?

amitkalo commented 4 years ago

As I say on the comment, it’s not worked and I get the runtime error that newRef dont have property native since its not a ‘ GeoDocumentReference’

MichaelSolati commented 4 years ago

What version of geofirestore are you using?

amitkalo commented 4 years ago

"geofirestore": "^3.4.1"

MichaelSolati commented 4 years ago

Can you please provide a GitHub repo or StackBlitz where this issue is reproducible?