google-cloud-firestore

How to transform the data received from cloud_firestore into a Map

半腔热情 提交于 2020-01-24 19:24:05
问题 The data from the cloud_firestore database is in the form of JSON. However, how to transform the data from JSON in a List of Map? The dummy data in my firestore 回答1: Data to List of Map: final CollectionReference ref = Firestore.instance.collection('food'); List<Map<String, dynamic>> listOfMaps = []; await ref.getDocuments().then((QuerySnapshot snapshot) { listOfMaps = snapshot.documents.map((DocumentSnapshot documentSnapshot) { return documentSnapshot.data; }).toList(); }); print(listOfMaps)

With Firestore, how do I serialize a reference type field in a document with a java class?

落爺英雄遲暮 提交于 2020-01-24 08:50:06
问题 If I have a Firestore document with a field of type "reference", how do I read and write that field when using automatic POJO Java object serialization? 回答1: POJO fields of type DocumentReference and CollectionReference will automatically be populated with document and collection reference type fields from a Firestore document. 来源: https://stackoverflow.com/questions/49225103/with-firestore-how-do-i-serialize-a-reference-type-field-in-a-document-with-a-j

Firestore security rules based on request query value

可紊 提交于 2020-01-24 05:24:29
问题 I'm trying to secure requests to a collection to allow any single get , but only to allow list if a specific key is matched. Database structure is like this: projects project1 name: "Project 1 name" board_id: "board1" project2 name: "Project 2 name" board_id: "board2" boards board1 board2 The Firestore query I'm making from Vue: // Only return projects matching the requested board_id db .collection("projects") .where("board_id", "==", this.board_id) The security rules I'd like to have would

Firebase Firestore: orderBy combined with where causes error “Operation was rejected”

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-24 03:03:19
问题 I am looking at the Firebase Cloud Firestore documentation for orderBy. When I try to execute this var facultyQuery = facultyRef.where("department", "==", "Core Teacher").orderBy('bb_last_name', 'desc'); I get the error: Error: Firestore: Operation was rejected because the system is not in a state required for the operation`s execution. (firestore/failed-precondition). Both of these simpler cases work just fine: var facultyQuery = facultyRef.orderBy('bb_last_name', 'asc'); var facultyQuery =

Batched Writes or Transaction in Cloud Functions? [duplicate]

末鹿安然 提交于 2020-01-24 01:26:07
问题 This question already has an answer here : Is there any benefit to Batched Writes over Transactions other than offline availability? [closed] (1 answer) Closed 7 months ago . I have the following Cloud Function and want to find out whether I should use batched writes or a transaction: const firestore = admin.firestore() // The following two queries potentially return hundreds of documents. const queryA = firestore.collectionGroup('a').where('b', '==', 'c'), queryB = firestore.collection('b')

Flutter: How can i send push notification programmatically with fcm

假装没事ソ 提交于 2020-01-24 01:03:50
问题 I'm creating a chat application and i want to use fcm to send notification if the person has a new message, but i don't know how to proceed. All the tutorials i found use to send the message from firebase. But i want to send it automatically when there is a new message for the person 回答1: I'll list here a few related questions which I have participated with answers. I guess you'll find a lot of relevant info on using firebase cloud messaging (FCM) in a chat app. Is FCM the only way to build a

firestore — Add element in a field in hashmap

一世执手 提交于 2020-01-23 20:30:08
问题 Above is the structure of collection "networks". What is want to do is add another element in "users" field. It's a HashMap . I want to achieve is Key= xyz@gmail.com and its values {displayName: "Anirudh Kumar", "role":"admin"}. xyz@gmail.com displayName: "Anirudh Kumar" role: "admin" I have tried few things but it doesn't seems to work. 1st option Map<String, Network.NetworkUser> users = new HashMap<>(); users.put(email, networkUser); db.collection("networks").document("id") .update("users"

Firestore: Get subcollection of document found with where

£可爱£侵袭症+ 提交于 2020-01-23 17:55:08
问题 I am trying to get the documents inside an subcollection which is part of an document found with the .where function Exemple: RootColl/ Doc A/ SubColl 1 Doc 1 Doc 2 Doc 3 SubColl 2 Docs Doc A/ SubColl 1 Doc 1 Doc 2 Doc 3 SubColl 2 Docs I want to get all the documents under SubColl 1 from the doc with the field level == 1 I am trying to do it like: db.collection("RootColl").where("field", "==", "1").collection("SubColl 1").get() But by doing that i get the error Uncaught TypeError: db

Managing createdAt timestamp in Firestore

≡放荡痞女 提交于 2020-01-23 14:12:13
问题 Every day I am importing products from external retailers into a Google Cloud Firestore database. During that process, products can be either new (a new document will be added to the database) or existing (an existing document will be updated in the database). Should be noted that I am importing about 10 million products each day so I am not querying the database for each product to check if it exists already. I am currently using set with merge, which is exactly what I need as it creates a

How can I get specific document data from firestore querysnapshot?

大兔子大兔子 提交于 2020-01-23 12:05:33
问题 I got a querysnapshot in a function. And want to bring the whole querysnapshot to another function (functionTwo). In functionTwo, I want to get a specific document in the querysnapshot WITHOUT forEach. The specific doc can be changed by different case. ref_serial_setting.get() .then(querysnapshot => { return functionTwo(querysnapshot) }) .catch(err => { console.log('Error getting documents', err) }) let functionTwo = (querysnapshot) => { // getting value const dataKey_1 = "dataKey_1" // Tried