Unable to remove document reference from array using firebase.firestore.FieldValue.arrayRemove(docRef)

404 views
Skip to first unread message

jps...@mobials.com

unread,
Mar 27, 2019, 4:34:24 PM3/27/19
to Firebase Google Group
I've got a few collections, notably one for users and one for assets. When a user adds an asset, a reference to the asset document in its collection is added to 'userAssets' array in the user's document. That seems to work fine, and can be read and used to fetch the documents.

Later, when the user tries to remove the asset, I can remove the asset from the collection, but can't remove the reference to it in the user document.

I've tried creating a string that looks like what's in the array based off the web console:
await userRef.update({
assetKeys: firebase.firestore.FieldValue.arrayRemove(`/assets/${assetId}`),
});
That doesn't remove the reference, and doesn't give any error in the console.

I've also tried just using the document reference itself:

await userRef.update({
assetKeys: firebase.firestore.FieldValue.arrayRemove(docRef),
});
That just gives an error that doesn't help a whole lot:

Uncaught (in promise) FirebaseError: Function FieldValue.arrayRemove() called with invalid data. Unsupported field value: a custom DocumentSnapshot object

So what is it that I'm supposed to use to remove an document reference from an array in a document?

JP 
Reply all
Reply to author
Forward
0 new messages