I'm trying to create a new document under the collection "accounts" (this is working), and then add the ID of the newly created account to an array of accounts the current user has access to (array is called accountAccess). Here's the function:
async function addAccount(accountName, id) {
await db.collection('accounts').add({
name: accountName,
owner: id
}).then(async (account) => {
const accountIdToAdd = db.FieldValue.arrayUnion(account.id);
await db.collection('users').doc(userId).update({
accountAccess: accountIdToAdd,
});
});
}
But I receive the error `[Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_firebase.db.FieldValue.arrayUnion')]
Any ideas what I'm doing wrong in the then block?