Johan Lhour
Johan Lhour

Reputation: 31

Firebase FieldValue.arrayUnion() not working properly on client SDK

When I try to create an array in firestore with this code

await store
    .collection("video")
    .doc(videoId)
    .set(
      {
        data: firebase.firestore.FieldValue.arrayUnion(userId),
      },
      {merge: true},
    )

The data created in firestore then look like

this

Upvotes: 2

Views: 944

Answers (2)

Johan Lhour
Johan Lhour

Reputation: 31

This behavior appear because I was using firestore from @react-native-firebase/firestore and importing firebase from firebase library instead of @react-native-firebase/app so i had to change this

import firebase from "firebase"

To this

import firebase from "@react-native-firebase/app"

Upvotes: 1

MarketerInCoderClothes
MarketerInCoderClothes

Reputation: 1236

First, omit the trailing comma after {merge:true}.

If that doesn't fix it, can you share how you define "userId" and "store"?

Upvotes: 0

Related Questions