google-cloud-firestore

What is the JSON format for a firestore individual field index within a collection group query?

僤鯓⒐⒋嵵緔 提交于 2020-04-16 03:56:06
问题 We can now retrieve documents from a collection group which is great. To do so, I need to create an index through an error message on the Firebase console. How can I add this new index to the firestore.indexes.json file? Example of the documentation: let museums = db.collectionGroup('landmarks').where('type', '==', 'museum'); museums.get().then(function(querySnapshot) { querySnapshot.forEach(function(doc) { console.log(doc.id, ' => ', doc.data()); }); }); 回答1: At the top level of your index

What is the JSON format for a firestore individual field index within a collection group query?

纵然是瞬间 提交于 2020-04-16 03:55:00
问题 We can now retrieve documents from a collection group which is great. To do so, I need to create an index through an error message on the Firebase console. How can I add this new index to the firestore.indexes.json file? Example of the documentation: let museums = db.collectionGroup('landmarks').where('type', '==', 'museum'); museums.get().then(function(querySnapshot) { querySnapshot.forEach(function(doc) { console.log(doc.id, ' => ', doc.data()); }); }); 回答1: At the top level of your index

Flutter + Firebase. Sorting data in chronological order

馋奶兔 提交于 2020-04-16 03:46:30
问题 I add some data to the collection. When i retrive it, it is sorted by that generated id. Is it posible to make firebase to sort it in chronological order or it is required to add one more field with date and sort it once it is retrived in flutter? 回答1: Yes you need a createdAt timestamp field and use it like Firestore.instance .collection("users") .orderBy('createdAt', descending: true or false).getDocuments() And you can store createdAt on flutter side with Timestamp (Its included in cloud

How to compare firebase timestamps?

烂漫一生 提交于 2020-04-16 03:20:53
问题 I have cloud function code code like this: console.log(`ts: ${(element.get('expire') as admin.firestore.Timestamp).toDate().toUTCString()} now: ${admin.firestore.Timestamp.now().toDate().toUTCString()}`) const greater = (element.get('expire') as admin.firestore.Timestamp) > admin.firestore.Timestamp.now() const lower = (element.get('expire') as admin.firestore.Timestamp) < admin.firestore.Timestamp.now() console.log(`greater: ${greater} lower: ${lower}`) In console: ts: Mon, 08 Apr 2019 20:59

How to compare firebase timestamps?

强颜欢笑 提交于 2020-04-16 03:20:06
问题 I have cloud function code code like this: console.log(`ts: ${(element.get('expire') as admin.firestore.Timestamp).toDate().toUTCString()} now: ${admin.firestore.Timestamp.now().toDate().toUTCString()}`) const greater = (element.get('expire') as admin.firestore.Timestamp) > admin.firestore.Timestamp.now() const lower = (element.get('expire') as admin.firestore.Timestamp) < admin.firestore.Timestamp.now() console.log(`greater: ${greater} lower: ${lower}`) In console: ts: Mon, 08 Apr 2019 20:59

How to compare firebase timestamps?

我的未来我决定 提交于 2020-04-16 03:19:20
问题 I have cloud function code code like this: console.log(`ts: ${(element.get('expire') as admin.firestore.Timestamp).toDate().toUTCString()} now: ${admin.firestore.Timestamp.now().toDate().toUTCString()}`) const greater = (element.get('expire') as admin.firestore.Timestamp) > admin.firestore.Timestamp.now() const lower = (element.get('expire') as admin.firestore.Timestamp) < admin.firestore.Timestamp.now() console.log(`greater: ${greater} lower: ${lower}`) In console: ts: Mon, 08 Apr 2019 20:59

Firestore order and limit data returns missing results

亡梦爱人 提交于 2020-04-16 02:55:10
问题 I want to do a few things when I fetch for user records in Firestore: filter users within an age range filter users based on gender, location, and favorite fruits get the last 6 recently joined users get users created before today func observeUsers(){ let fruits: [String] = ["none"] let location = "Paris" let gender = "male" let startAge = 15 let endAge = 30 let today: Double = Date().timeIntervalSince1970 var query = db.collection("users") as Query if(!fruits.isEmpty) { query = query

Use value from form to render specific data from firebase

為{幸葍}努か 提交于 2020-04-16 02:29:13
问题 I'm trying to render data from my Firebase Firestore DB after a user enters a control number from a form. This is SingleQuery hook a.k.a. the listener to my Firestore DB //Code to Query data from Database function SingleQuery() { const [drivers, setDrivers] = useState([]); useEffect(() => { const unsubscribe = firebase .firestore() .collection("drivers") .where("controlNumber", "==", {{CONTROL NUMBER FROM FORM}}) //get data according to control number .onSnapshot(snapshot => { const newDriver

Use value from form to render specific data from firebase

懵懂的女人 提交于 2020-04-16 02:28:31
问题 I'm trying to render data from my Firebase Firestore DB after a user enters a control number from a form. This is SingleQuery hook a.k.a. the listener to my Firestore DB //Code to Query data from Database function SingleQuery() { const [drivers, setDrivers] = useState([]); useEffect(() => { const unsubscribe = firebase .firestore() .collection("drivers") .where("controlNumber", "==", {{CONTROL NUMBER FROM FORM}}) //get data according to control number .onSnapshot(snapshot => { const newDriver

How to log errors with Firebase Hosting for a deployed Angular web app

假如想象 提交于 2020-04-15 10:51:09
问题 I am working on an Angular single page web app which uses Firestore as the database and will be deployed to Firebase Hosting. There seems to be no built-in way to log errors to the server or get run-time analytics unless you are developing an Android or iOS mobile app. I want to be able to view the web log files and find out about errors or abuse and see other typical live usage data. For example if the database code throws an error or a web API call returns an unexpected value and I catch