jjzjj

Firestore

全部标签

javascript - Cloud Functions - Cloud Firestore 错误 : can't get serverTimestamp

CloudFunctions-CloudFirestore错误:无法获取服务器时间戳constadmin=require('firebase-admin');exports.userlog=functions.firestore.document('user/{userId}').onUpdate((change,context)=>{constdb=admin.firestore();//vartimestamp=db.FieldValue.serverTimestamp();vartimestamp=db.ServerValue.TIMESTAMP;...returndb.coll

javascript - Firestore + 云函数 : How to read from another document

我正在尝试编写一个从另一个文档读取的Google云函数。(其他文档=不是触发云功能的文档。)弄清楚如何做这么简单的事情有点像寻宝。云功能文档似乎建议查看管理SDK:“您可以通过DeltaDocumentSnapshot界面或管理SDK进行CloudFirestore更改。”https://firebase.google.com/docs/functions/firestore-eventsAdminSDK建议编写以下代码行来获取客户端。但是哦,不,它不会解释客户。它将让我们在文档的其他地方进行徒劳的追逐。vardefaultFirestore=admin.firestore();“如果

javascript - firestore 查询中的条件 where 子句

我已经从firestore获取了一些数据,但在我的查询中我想添加一个条件where子句。我正在为api使用async-await,但不确定如何添加条件where子句。这是我的功能exportasyncfunctiongetMyPosts(type){awaitapivarmyPosts=[]constposts=awaitapi.firestore().collection('posts').where('status','==','published').get().then(snapshot=>{snapshot.forEach(doc=>{console.log(doc.data

javascript - 如何使函数与 Firestore 一起工作?

函数/index.js:constfunctions=require('firebase-functions')constadmin=require('firebase-admin')admin.initializeApp(functions.config().firebase)constdb=admin.database().ref()exports.app=functions.https.onRequest((req,res)=>{//dowhateverhere...db.child('something').once('value').then(snap=>console.lo

javascript - 如何使用 firestore 执行动态 where 查询并添加索引

在我的网站上,我正在进行类似测试的调查,每个测试都有attendies子集合,看起来像这样当有人完成测试时,我也会将他们的uid添加到completed字段,就像我在框中绘制的那样。现在我想根据status==completed查询tests。这是我尝试过的this.completedModulesRef$=this.afs.collection('tests',ref=>ref.orderBy('moduleNum','desc').where('completed.'+auth.uid+'.status','==','completed'));this.completedModul

javascript - firestore 数据结构的最佳实践是什么?

我正在使用firebase制作博客应用。我想知道数据结构的最佳实践。据我所知,有两种情况。(我正在使用nativereact)案例一:posts-postID-title,content,author(userID),createdDate,favoriteCountfavorites-userID-favoriteList-postID(onlyID)-postID(onlyID)在这种情况下,例如,当我们需要获取最喜欢的帖子时。firebase.firestore().collection(`favorites/${userID}/favoriteList`).get().then

javascript - 如何在 Firestore 文档中保存对 Firebase Auth 用户的引用?

所以我有一个应用程序,您可以在其中注册和登录。我使用FirebaseAuth做到了这一点。然后我有一个Firestore,其中有多个集合,例如“请求”和“要约”。我的应用程序中的Firebase授权用户可以创建新的请求,我是这样添加的:firestore.collection('requests').add({category:'Test',customer_id:this.props.appState.user.uid,//TheuidfromFirebaseAuthlink:this.state.productLink}).then(docRef=>{console.log('Su

javascript - Firestore 无法获取空文档

我有文档的集合,其中文档的ID是用户ID。让我们调用这些用户文档。每个“用户文档”都包含聊天消息的子集。但并非所有“用户文档”都包含任何字段(数据,子集合除外)。我不想返回集合中没有任何字段但有子集合的所有文档,但我觉得这不可能?varallUserDocs={},count=0,users=firestore.collection("users");users.get().then(snapshot=>{snapshot.forEach(doc=>{count++;allUserDocs[count]=doc.data();});allUserDocs.count=count;res

reactjs - Firestore 按数组的字段值查询

我正在尝试运行一个简单的查询,我在其中搜索包含对象数组中的值的文档。例如,看看我的数据库结构:我想运行与此类似的查询:db.collection('identites').where("partyMembers","array-contains",{name:"JohnTravolta"})实现此目标的正确方法是什么,甚至可以使用Firestore吗?谢谢。 最佳答案 正如Frank在他的回答中所解释的那样,使用数组包含查询存储在数组中的对象的特定属性是不可能的。但是,有一个可能的解决方法:实际上可以查询整个对象,如下所示,在您的情

javascript - Firebase Firestore : orderBy combined with where causes error "Operation was rejected"

我正在查看FirebaseCloudFirestoredocumentation对于orderBy。当我尝试执行此操作时varfacultyQuery=facultyRef.where("department","==","CoreTeacher").orderBy('bb_last_name','desc');我得到错误:Error:Firestore:Operationwasrejectedbecausethesystemisnotinastaterequiredfortheoperation`sexecution.(firestore/failed-precondition).这