Tag: google cloud firestore

在Es6中导入DocumentReference

像DocumentReference,CollectionReference等类,似乎没有出口。 有没有办法导入这些类?

如何在Node.js中查询Firebase Firestore集合的子集?

我是Firestore的新手,所以我有一个简单的问题: 假设我有一组用户和一组组 。 用户有一个groupReferences的数组字段来标记它所属的 组 。 现在我想查询与特定用户相匹配的组的集合的子集。 我是否: 拉所有组,并以某种方式比较用户中的参考,过滤出任何匹配? 迭代用户的引用,并一次拉一个组 ? 谢谢你的帮助!

将Firestore依赖项和types导入到node.js

我最近在今年的FirebaseSummit会谈后将我的云function更新到了TypeScript 。 我所有的代码看起来相当酷,但我有一些问题,试图恢复types的Firestore API,如QuerySnapshot , DocumentReference … async function getEventsMadeByUser(userId: string): Promise<FirebaseFirestore.DocumentSnapshot[]> { const eventsMadeByUserQuery = await instance.collection('PrivateUserData') .doc(userId).collection(EVENTS) .where('interactionUser', '==', userId).get(); return eventsMadeByUserQuery.docs; } 现在我的IDE(WebStorm)没有获取FirebaseFirestore的types。 这是我的package.json外观: { "name": "functions", "description": "Cloud Functions for Firebase", "dependencies": { "firebase-admin": "^5.4.3", "firebase-functions": "^0.7.2" }, "devDependencies": { "@types/express": "^4.0.37", "typescript": "^2.3.2" }, "scripts": { "build": "tsc", "watch": "tsc […]

更新检索的Firestore文档?

我磕磕绊绊地find一个我觉得很傻的问题,但似乎无法解决: 我不能直接更新从Firestore检索的文档。 例如,当我尝试在onWrite触发器中将以下代码部署到其他节点时: admin.firestore().collection("user-data").doc('someUserId').get().then(doc => { const profile = doc.data() if (profile.foo != 'bar') { return 0 } return doc.update({ objectToUpdate: { fieldToUpdate: 'Foo is not bar!'} }) 我得到的错误, doc.update is not a function 我也试过doc.ref.update和doc.data.ref.update ,但没有骰子。 我可以用admin.firestore().collection("user-data').doc('someUserId').update({…})来达到我想要的admin.firestore().collection("user-data').doc('someUserId').update({…}) ,但是感觉太笨重了… 我在这里错过了什么?

使用.limit()和Firestore查询

我有一个使用Firestore作为队列的应用程序。 数据来自另一个来源,存储在Firestore的/data/{id} , unprocessed的属性设置为true。 在我的Node.js脚本中,我想要一次查询这些未处理的logging,以缓慢地处理它们。 有成千上万的logging,所以试图将它们全部加载到内存中会使进程崩溃。 码: firestore.collection('data').where('unprocessed', '==', true).limit(25).onSnapshot((snapshot) => { snapshot.forEach((doc) => { processItem(doc); }); }); processItem()函数执行必要的处理,将数据保存回Firestore, unprocessed属性设置为false。 我正在运行的问题是,任何时候我试图运行这个代码,我得到以下错误: Error: Error 3: Order must include __name__ at sendError (C:\[myApp]\node_modules\@google-cloud\firestore\src\watch.js:254:15) at DestroyableTransform.stream.on.proto (C:\[myApp]\node_modules\@google-cloud\firestore\src\watch.js:532:13) at emitOne (events.js:115:13) at DestroyableTransform.emit (events.js:210:7) at addChunk (C:\[myApp]\node_modules\readable-stream\lib\_stream_readable.js:284:12) at readableAddChunk (C:\[myApp]\node_modules\readable-stream\lib\_stream_readable.js:271:11) at DestroyableTransform.Readable.push (C:\[myApp]\node_modules\readable-stream\lib\_stream_readable.js:238:10) at DestroyableTransform.Transform.push (C:\[myApp]\node_modules\readable-stream\lib\_stream_transform.js:146:32) at afterTransform (C:\[myApp]\node_modules\readable-stream\lib\_stream_transform.js:102:51) […]

如何在Cloud Functions Firestore中处理读写操作

我有点困惑如何重构我的代码读取和写入没有嵌套的承诺。 在写入对象时,如果该对象有一个标志设置,我想用新的计数来更新它的“相关”对象。 我有两个问题。 1)嵌套承诺从读取然后写入。 2)我应该回来什么 exports.updateRelationshipCounts = functions.firestore .document('masterProduct/{nfCode}').onWrite((event) => { //on writing of record: var newProduct = event.data.data(); if (newProduct.isGlutenFreeYN === 'Y') { console.log('Gluten Free'); //Update GF count in the Brand Object: var db = admin.firestore(); var docRef = db.collection("masterBrand").doc(newProduct.brandNFCode); var doc = docRef.get() .then(doc => { doc.glutenFreeCount = doc.glutenFreeCount + 1 docRef.set(newProduct.brand) .then(function […]

Firebase云function与云Firestore的麻烦

我在以前的项目中使用过这个Firebase数据库代码: const getDeviceUser = admin.database().ref(`/users/${notification.to}/`).once('value'); 我现在正试图将其转换为Firestore。 我基本上是试图让我的用户fcm当通知正在发送。 我已经尝试了很多东西,但还没有看到实现这一目标的新方法。 编辑:这是我的代码。 exports.sendFavoriteNotification = functions.firestore.document('users/{userUid}/notifications/{notificationId}').onCreate(event => { const notification = event.data.data(); const user = event.params.userUid; const getDeviceUser = admin.database().ref(`/users/${notification.to}/`).once('value'); // Get the follower profile. const getProfilePromise = admin.auth().getUser(notification.sender); return Promise.all([getDeviceUser, getProfilePromise]).then(results => { const tokensSnapshot = results[0]; const liker = results[1]; // Check if there are any device […]

如何使用node.js代码在Firestore中创build一个集合

我无法弄清楚如何用node.js firestore api创build一个新的Collection。 有什么build议么?

在从我的承诺/function返回之前等待forEach完成

我正在使用Firebase Cloud Firestore,但是,我认为这可能是更多的JavaScriptasynchronous与同步承诺返回问题。 我正在做一个查询来从一个集合中获取ID,然后循环查询的结果从另一个集合中查找基于该ID的单个logging。 然后我想将每个find的logging存储到一个数组中,然后返回整个数组。 results.length始终为0,因为return results在forEach完成之前触发。 如果我从forEach内部打印results.length它有数据。 我怎么才能等到forEach完成之后才从外部承诺和外部函数本身返回呢? getFacultyFavoritesFirebase() { var dbRef = db.collection("users").doc(global.user_id).collection("favorites"); var dbQuery = dbRef.where("type", "==", "faculty"); var dbPromise = dbQuery.get(); var results = []; return dbPromise.then(function(querySnapshot) { querySnapshot.forEach(function(doc) { var docRef = db.collection("faculty").doc(doc.id); docRef.get().then(function(doc) { if (doc.exists) { results.push(doc); } }) }); console.log(results.length); return results; }) .catch(function(error) { console.log("Error getting […]

ORM for firestore

是否有任何支持nodejs中的firestore的ORM? 我特别喜欢Python中的ndb。