google-cloud-firestore

How can I check if a value e.g. name exists in a collection within any of documents in Cloud Firestore?

妖精的绣舞 提交于 2021-02-17 06:44:05
问题 I want to check if a value e.g. (name: ‘John’) exists in the collection of any document in my Cloud Firestore, because if it does I do not want to create a new document with that name (in this case ‘John’). How can I check if the name exists? 回答1: Assuming you have in Firestore a collection called "users", to check if a user with the name of "John" already exists, please use the following lines of code: FirebaseFirestore rootRef = FirebaseFirestore.getInstance(); CollectionReference usersRef

Add nested data in Firestore by flutter

倖福魔咒の 提交于 2021-02-17 06:30:27
问题 I'm from following issue. How to manage add and update data in Firebase Initially I can make data in firestore following code. However I would like to add car2 inside of cars after car1 . I have no idea of it. _firestore.collection('members').document(${loginUser.uid}).setData({ 'cars': { 'car1': { 'name': name, 'img_url': 'https://www.xxx.xxx/xxx.png', 'details': { 'type': carType, } } } Please give me advice. 回答1: To add cars2 , then do the following: _firestore.collection('members')

Can't assign a value to variable inside of closure Swift [duplicate]

冷暖自知 提交于 2021-02-17 06:24:08
问题 This question already has answers here : Returning data from async call in Swift function (11 answers) Closed 9 months ago . I'm trying to get current document count belongs to spesific user from Firebase. Whenever i try to assign count value to my variable in closure, value is always shown as nill. So that i did couple of research, as a result i figured out networking sometimes takes so long and it happens asynchronously. So if i'm not wrong due to asynchronous returning a value inside a

Referencing Firebase realtime database data through firestore security rules

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-17 06:14:06
问题 I would like to use data in the realtime database to allow user access in the firestore database. Is it possible to reference nodes in the realtime database from the firestore security rules? 回答1: It is currently not possible to cross between database products like this in security rules. Please feel free to file a feature request for this. You can, however, write code to run on Cloud Functions that deals with database changes after the change has happened, and undo or restrict the change

Firestore delete vs update time and performance

妖精的绣舞 提交于 2021-02-17 05:38:07
问题 I have coded a match making system and this system works like that --> when a create operation came to firestore it matches with an older record and the cloud function deletes both of them. But i wonder that when 2 new records are created, is there any chance for matching these 2 with the same old record because the deletion process takes some time? Also, if i do that process with update, is it faster than delete? EDIT: Here is my matchMaker Cloud Function: exports.matchMaker = functions

How to fetch data from two firestore collection, merge and display it

徘徊边缘 提交于 2021-02-17 05:20:12
问题 I have two collections namely CURRENCY_PAIR and CURRENCY_PAIR_LIMIT . The CURRENCY_PAIR collection has the following fields in each document: CurrencyPair_Name CurrencyPair_id Currency_AskPrice Currency_BidPrice and the CURRENCY_PAIR_LIMIT collection contain the following fields in each document: Limit_id Limit_Buy_Price_Threshhold Limit_Sell_Price_Threshhold Limit_Currency_Pair_Id (references to the Currencypair_Id in the CURRENCY_PAIR collection) I wanted to map each CurrencyPair_Name to

How to paginate data in Firebase in Next.js SSR app?

走远了吗. 提交于 2021-02-16 21:48:48
问题 I am trying to build a next.js server-side rendered blog. For it, I need to paginate the posts data. However, I am yet to find a way to use the query cursors firebase provides to paginate the data. The building query code is: let postsQuery = firebase.firestore().collection('/posts').orderBy('postedOn', 'asc').limitToLast(10); if (currentTagFilter !== 'All') { postsQuery = postsQuery.where('tag', '==', currentTagFilter); } Now, this works for the first page, but I do not know how to request

Way to query and update data in Firestore

左心房为你撑大大i 提交于 2021-02-16 20:07:53
问题 I run a payment system with Stripe and am trying to decrement a quantity field in Firestore after every successful purchase. I can get the document but I'm struggling figuring out how to update it. db.collection('products').where('id', '==', dbRef).get() .then(querySnapshot => { return querySnapshot.forEach(doc => { return res.json({ data: doc.data(), err: err }) }) }) { "data": { "stripe": { "sku": "sku_xxx", "product": "prod_xxx" }, "name": "VERSA HOODIE", "id": "pmz0pvfa", "createdBy":

Firebase Cloud Messaging : Expiration of FCM token

强颜欢笑 提交于 2021-02-16 20:07:16
问题 I understand that the FCM token renews itself if one of the following happens. -The app deletes Instance ID -The app is restored on a new device -The user uninstalls/reinstall the app -The user clears app data. The following can be used at the App side to monitor Token renewal. Monitor token generation The onTokenRefreshcallback fires whenever a new token is generated, so calling getToken in its context ensures that you are accessing a current, available registration token. Make sure you have

Wait for Firestore queries to complete

非 Y 不嫁゛ 提交于 2021-02-16 15:28:28
问题 I am currently trying to run multiple queries in firestore and want to wait for them to all complete before executing the next code. I've read up on several possible avenues but I have yet to find a good Android example. public HashMap<String,Boolean> multipleQueries(String collection, String field, final ArrayList<String> criteria) { HashMap<String,Boolean> resultMap = new HashMap<>(); for (int i = 0; i < criteria.size(); i++){ final int index = i; db.collection(collection).whereEqualTo