[英]Removing an object (map) from array based on its values on firestore
使用此线程作为参考如何从 firestore 中的数组中删除 object我想进一步了解如何从 firestore 中的数组中删除 object。
我的firestore设置如下:
Users(collection) -> 12345(document) -> myArray:[{x:"hello", y:"please"}, {x:"hello", y:"thanks"}]
我正在尝试根据其值对特定的 object 进行数组删除。
这是我当前的代码,尽管阅读了其他帖子说它应该工作,但它不起作用。
import firestore from '@react-native-firebase/firestore'; //EDIT
let obj = {x:"hello", y:"thanks"}
firestore()
.collection("Users")
.doc("12345")
.update({
myArray: firestore.FieldValue.arrayRemove(obj),
}).then(r =>console.log("YEAAAH"))
关于我可以尝试什么的任何建议? 或任何好的解决方法?
PS 我在我的 React Native 应用程序的客户端执行此操作,我宁愿不必调用端点。
目前尚不清楚如何声明您在代码中使用的firestore()
方法和firestore
变量:
firestore() <= What exactly is firestore()?
.collection("Users")
.doc("12345")
.update({
myArray: firestore.FieldValue.arrayRemove(obj), <= What exactly is firestore?
})
.then(r =>console.log("YEAAAH"))
您没有说明您是否正在使用带有模块的捆绑器,但以下代码(没有捆绑器)可以解决问题:
var config = {
....
};
firebase.initializeApp(config);
let obj = { x: 'hello', y: 'thanks' };
firebase.firestore() // Note the difference
.collection('Users')
.doc('12345')
.update({
myArray: firebase.firestore.FieldValue.arrayRemove(obj), // Note the difference
})
.then((r) => console.log('YEAAAH'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.