如果您对如何使用JavaScript根据CloudFirestore中的查询删除数组中的对象感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于如何使用JavaScript根据C
如果您对如何使用 JavaScript 根据 Cloud Firestore 中的查询删除数组中的对象感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于如何使用 JavaScript 根据 Cloud Firestore 中的查询删除数组中的对象的详细内容,我们还将为您解答js从数组中查找某个元素并删除的相关问题,并且为您提供关于(Flutter) 如何使用 Cloud Functions for Firebase 从 Firestore 检索文档、@firebase/firestore: Firestore (8.6.2): 无法访问 Cloud Firestore 后端 (React Js)、@firebase/firestore:Firestore (8.3.3):无法访问 Cloud Firestore 后端、@firebase/firestore:Firestore (8.6.5):无法访问 Cloud Firestore 后端的有价值信息。
本文目录一览:- 如何使用 JavaScript 根据 Cloud Firestore 中的查询删除数组中的对象(js从数组中查找某个元素并删除)
- (Flutter) 如何使用 Cloud Functions for Firebase 从 Firestore 检索文档
- @firebase/firestore: Firestore (8.6.2): 无法访问 Cloud Firestore 后端 (React Js)
- @firebase/firestore:Firestore (8.3.3):无法访问 Cloud Firestore 后端
- @firebase/firestore:Firestore (8.6.5):无法访问 Cloud Firestore 后端
如何使用 JavaScript 根据 Cloud Firestore 中的查询删除数组中的对象(js从数组中查找某个元素并删除)
如何解决如何使用 JavaScript 根据 Cloud Firestore 中的查询删除数组中的对象
我想使用 JavaScript 根据 Cloud Firestore 中的查询删除数组中的对象
这是我的数据库结构:
数组是“reserved_items”,里面有多个对象。 如果“uniqueBarcode”与对象中的“Barcode”匹配,我想删除其中一个对象
这是我迄今为止尝试过的:
viewData = null
console.log(uniqueBarcode)
db.collection("users").where("uid","==",uid).where("Barcode",uniqueBarcode)
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
viewData = doc.data().wishlist;
console.log(viewData)
});
})
.catch((error) => {
console.log("Error getting documents: ",error);
});
“uniqueBarcode”是条码的值
解决方法
如果您打算单独查询数组元素,通常不要将数组存储在 Firestore 或 RTDB 中。而是将 reserved_items
存储为子集合并使用唯一的条形码作为它们的键,然后您可以像这样删除单个文档:
db.doc(`users/${uid}/reserved_items/${barcode}`).delete().then(
() => console.log("That was easy")
);
然而,要回答您的具体问题,您需要检索数组,在客户端对其进行修改,然后将其保存回您的文档。
const ref = firebase.firestore().doc(`users/${uid}`);
ref.get(''reserved_items'').then(async (doc) => {
let arr = doc.data();
if (arr.reserved_items.length > 0) {
// Filter out all array elements that match uniqueBarcode
arr.reserved_items = arr.reserved_items.filter(ele => ele.barcode !== uniqueBarcode);
// Update Firestore with the filtered array
await ref.update(arr);
}
console.log("Done!");
});
(Flutter) 如何使用 Cloud Functions for Firebase 从 Firestore 检索文档
如何解决(Flutter) 如何使用 Cloud Functions for Firebase 从 Firestore 检索文档
我正在尝试在 Node.js 中编写云函数。
该函数需要以 json 形式返回 Cloud Firestore 文档数据。
我已经阅读了 document,我可以在其中找到可以在 Cloud Firestore 事件(例如 onCreate 和 onDelete)上触发 Cloud Functions。
但是,除了这些事件之外,文档没有更新或删除,我想知道是否可以使用 functions.firestore
对象来完成。
有可能吗?或者我应该只使用 Cloud Firestore 的 REST API 并创建诸如 functions.https.onRequest
之类的东西。如果你选择后者,这在 Flutter 中应该如何实现?
解决方法
这听起来像你想使用云功能,创建了一个API,你的应用可以调用从公司的FireStore找回一些数据。这确实是可能的,而且实际上很常见。
在这种情况下,将实现无论是所谓的HTTP function或{一个{3}}执行通过Callable Cloud Function
与公司的FireStore必要的相互作用@firebase/firestore: Firestore (8.6.2): 无法访问 Cloud Firestore 后端 (React Js)
如何解决@firebase/firestore: Firestore (8.6.2): 无法访问 Cloud Firestore 后端 (React Js)
我正在尝试将我的 react js 应用程序与 Firebase Firestore 连接,但出现以下错误,如图 error image 我在集合中有 2 个文档,但我得到一个空的您可以在控制台中看到的数组。这是我用来获取 firestore 数据的代码
const snapshot = await firebase.firestore().collection(''users'').get();
const data = snapshot.docs.map((doc) => doc.data());
console.log(data);
PS:我可以正确使用来自 firebase 的 auth 功能,但在使用 firestore 时出现错误。
到目前为止我尝试过的解决方案:
- 同步时钟
- 验证了 firebase 规则并确保允许读写(附上我在 firestore 规则部分找到的规则)
rules_version = ''2'';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read,write: if
request.time < timestamp.date(2021,6,23);
}
}
}
自从昨晚以来我一直在努力寻找一些快速的解决方案。提前致谢。
解决方法
我尝试了以下步骤来确认 React 应用程序或浏览器存在问题并修复了问题。
尝试使用 node 和 express 获取数据并将数据发布到 Firestore 脚本(这有助于发现问题不在于 firebase 配置)
经过一些在线研究后,我尝试将浏览器从 Brave 更改为 真正有效的 Chrome。
屏幕截图中的第一个错误暗示这实际上是一个 Access-Control-Allow-Origin
CORS 问题。因此,为了像您在 this article 中看到的那样修复它,您可以:
- 将
"proxy": "http://localhost:PORT_YOU_ARE_USING"
选项添加到您的package.json
文件中;
或
- 使用像 http-proxy-middleware 这样的中间件来代理请求,您可以按照文章中的示例进行操作。
您还可以查看此 community question,它与您的问题类似,并提供了一些其他解决方案。通过查看,您可能会更好地了解 React 中的 cors 问题。
@firebase/firestore:Firestore (8.3.3):无法访问 Cloud Firestore 后端
如何解决@firebase/firestore:Firestore (8.3.3):无法访问 Cloud Firestore 后端
在添加了 eslint 并且没有更改代码之后,我运行了我昨天运行良好的应用程序。我最终收到以下错误:
[2021-04-09T04:47:33.960Z] @firebase/firestore: Firestore (8.3.3): Could not reach Cloud Firestore backend. Connection Failed 1 times. Most recent error: FirebaseError: [code=invalid-argument]: 3 INVALID_ARGUMENT: Invalid resource field value in the request.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
我也看到了一些其他的 stackoverflow 帖子和 github 问题,而且大多数人以前似乎也遇到过同样的问题。我尝试了一些建议的解决方案 - 降级 Firebase、检查我的互联网等 - 似乎没有任何效果。
@firebase/firestore:Firestore (8.6.5):无法访问 Cloud Firestore 后端
如何解决@firebase/firestore:Firestore (8.6.5):无法访问 Cloud Firestore 后端
我之前使用过 expo,但我退出了我的项目,一切正常,除了我的 firebase 连接。它说:@firebase/firestore: Firestore (8.6.5): 无法访问 Cloud Firestore 后端。后端没有在 10 秒内响应。
import firebase from ''firebase'';
import ''@firebase/firestore'';
const firebaseApp = firebase.initializeApp({
apiKey: ''AIzaSyALTdavPNQReVJNWyc2aF8DfexzxzDoXB0'',authDomain: ''projetofinal-e1147.firebaseapp.com'',projectId: ''projetofinal-e1147'',storageBucket: ''projetofinal-e1147.appspot.com'',messagingSenderId: ''546669005614'',appId: ''1:546669005614:web:1b06c375565e04b4c888bf'',measurementId: ''G-KLJBEWBR3S'',});
class Fire {
constructor(callback) {
this.init(callback);
}
init(callback) {
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
firebase.auth().onAuthStateChanged(user => {
if (user) {
callback(null,user);
} else {
firebase
.auth()
.signInAnonymously()
.catch(error => {
callback(error);
});
}
});
}
getLists(callback) {
let ref = this.ref.orderBy(''color'');
this.unsubscribe = ref.onSnapshot(snapshot => {
lists = [];
snapshot.forEach(doc => {
lists.push({id: doc.id,...doc.data()});
});
callback(lists);
});
}
addList(list) {
let ref = this.ref;
ref.add(list);
}
deleteList(list) {
let ref = this.ref;
ref.doc(list.id).delete();
}
updateList(list) {
let ref = this.ref;
ref.doc(list.id).update(list);
}
get userId() {
return firebase.auth().currentUser.uid;
}
get ref() {
return firebase
.firestore()
.collection(''users'')
.doc(this.userId)
.collection(''lists'');
}
detach() {
this.unsubscribe();
}
}
export default Fire;
这是我的 Firebase 文件,它在我的 expo 应用程序中工作,但不再是了。
解决方法
添加:
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
+ firebase.firestore().settings({ experimentalForceLongPolling: true,merge: true });
}
今天的关于如何使用 JavaScript 根据 Cloud Firestore 中的查询删除数组中的对象和js从数组中查找某个元素并删除的分享已经结束,谢谢您的关注,如果想了解更多关于(Flutter) 如何使用 Cloud Functions for Firebase 从 Firestore 检索文档、@firebase/firestore: Firestore (8.6.2): 无法访问 Cloud Firestore 后端 (React Js)、@firebase/firestore:Firestore (8.3.3):无法访问 Cloud Firestore 后端、@firebase/firestore:Firestore (8.6.5):无法访问 Cloud Firestore 后端的相关知识,请在本站进行查询。
本文标签: