无法在Firestore中使用arrayRemove。使用无效数据调用函数DocumentReference.update()

时间:2020-11-12 15:21:10

标签: javascript firebase google-cloud-firestore firebase-admin

当尝试使用“ arrayRemove”删除数组中的元素时,无法在我的代码中看到问题。

这是我的代码:

hcat(0, a)

ERROR: DimensionMismatch("mismatch in dimension 1 (expected 1 got 2)")

这是我的错误消息:

错误[FirebaseError]:函数DocumentReference.update()调用了无效数据。不支持的字段值:自定义对象(在文档客户/区域的字段预订中找到)

1 个答案:

答案 0 :(得分:0)

显然,您正在混用JS SDK和Admin SDK:

一方面,您这样做

const getRef = firebase.firestore().collection('customers').doc('andreas');  // JS SDK

另一方面,您这样做

bookings: admin.firestore.FieldValue.arrayRemove('123booking')  // Admin SDK

如果您实际上使用的是Admin SDK(请参阅问题标记),则应该这样做

const getRef = admin.firestore().collection('customers').doc('andreas');

另一方面,如果您未使用Admin SDK,即此代码是在网络应用中执行的,则将以下行更改为

bookings: admin.firestore.FieldValue.arrayRemove('123booking')

bookings: firebase.firestore.FieldValue.arrayRemove('123booking')
相关问题