I have an array of UIDs (String) and I want to perform a query using Firestore where I get all the documents in which the field "uid" is equal to any of the ones in the array provided.
Till now I tried doing:
ref.whereField("uid", in: uidArray)
But this doesn't work and gives me an error because the maximum number of elements in the array must be 10 and it surely surpasses that limit.
My question is: how can I achieve the same result with a workaround using Firestore?
Whenever I try to implement a query using this DB it seems it's built for making developers' lives harder.
Yes, according to the docs, the maximum number of elements in the array is 10. To be able to get over this limitation, you should perform successive calls. For example, if you need to check a field against 35 values, then you should perform 4 queries. Three queries with the 10 elements and the fourth with 5 elements. Lastly, you should combine the result on the client.
Related
I'm on migration from the old Google AdWords API to the new Google Ads API, using PHP-SDK by Google.
This is the use case, where I'm stuck:
I feed an amount of keywords (paginating them by keyword plans a 10k) to generateHistoricalMetrics($keywordPlanResource) and collect the results.
To do so I followed instructions at https://developers.google.com/google-ads/api/docs/keyword-planning/generate-historical-metrics and, especially, https://developers.google.com/google-ads/api/docs/keyword-planning/generate-historical-metrics#mapping_to_the_ui, with using of KeywordPlanAdGroupKeywords (with a single ad group) and avoiding to pass a specific date range for now, relying on the default value.
Further I had to apply some filters on my keywords because of KEYWORD_HAS_INVALID_CHARS and KEYWORD_TEXT_TOO_LONG, but all the errors which I'm aware of are gone now.
Now, I found out, that the KeywordPlanHistoricalMetrics object does not contain any keyword id (of the form customers//keywordPlanAdGroupKeywords/) So, I have to rely on the correct ordering. This is ok as it seems, that the original ordering of keywords is preserved within the results, as here https://developers.google.com/protocol-buffers/docs/encoding#optional
But still I have the problem, that
count($keywordPlanServiceClient->generateHistoricalMetrics($keywordPlanResource)->getMetrics()) is lower then count($passedKeywords), where each of $passedKeywords where passed to
new KeywordPlanAdGroupKeyword([
'text' => $passedKeyword,
'match_type' => KeywordMatchType::EXACT
'keyword_plan_ad_group' => $planAdGroupResource
]);
Q: So I have two questions here:
Why getMetrics() does not yield the same amount of results as the amount of passed keywords?
I'm struggling with debugging at this moment: Say, I want to know which keywords are let out. Either for providing more information at this place or just to skip them, and let my customer know, that these particular keywords were not queried. How to do this, when although I have a keyword id for every passed keyword I cannot match the returned metrics to them, because the KeywordPlanHistoricalMetrics object does not contain any keyword id.
Detail: While testing I found out, that the reducing of an amount of queried keywords reduces the amount of lost keyword data:
10k of queried keywords - 4,72% loss,
5k - 2,12%,
2,5k - 0,78%,
1,25k - 0,43%,
625 - 0,3%,
500 - 0,24%,
250 - 0,03%
200 - 0,03% of lost keywords.
But I can't imagine, that keywords should be queried one by one.
I am trying to generate a list containing the 'name' parameters as Strings from this Firestore.instance.collection('videos').limit(10).snapshots(); query, but I am having trouble extracting the parameter values from the documents and returning them as a list. Would I have to use .forEach() or do I have to .map() the entries to a list? Any help would be highly appreciated!
Edit: Additionally I would like to query the documents in a certain range, but .startAt() does not seem to accept integers. Is there any way to query say the first 10 documents by using Firestore.instance.collection('videos').startAt(0).limit(10).snapshots();?
There is an example of doing this using a StreamBuilder at https://pub.dartlang.org/packages/cloud_firestore#-example-tab-
Basically, my app has posts based on location that can be upvoted/downvoted.
I need to construct a query that returns the top 15 upvoted posts that lie in a specified region, and were made in the last 24 hours. Coming from an sql background, I am finding this unnecessarily difficult to do with the JSON format and firebase's built in query by order and filtering options. I realize i will most likely have to a lot of client side filtering, so I am asking what the JSON structure and query format would be to minimize client side filtering. So far this is what my JSON format looks like:
"posts" : {
"-KPFIsDbf3WUljWvBwi-" : {
"latitude" : 33.64114800203589,
"longitude" : -116.4236003651668,
"time" : 1.47129994542173E12,
"uid" : "wjXpBBJMBVPvRVG48fFkerAw6TD3",
"upvotes" : 0
},
I tried using Geofire, but unfortunately that seems to only have the ability to query by region, and since I want to query by region and time posted (among other things), using Geofire will not scale well.
Here's what I would do in a similar setup, using a combination of GeoFire and Firebase queries:
Step 1 (saving): When saving a post, save it to the database first, using a random ID. Then, grab that ID, create a GeoFire location, and set your post ID as the location key.
Step 2 (querying): This will be a 2 step query
Step 2a: Get all GeoFire locations within specified region. Now, you can grab the keys of all locations from the snapshots and and attach a single data event handler on each.
Step 2b: Maintain a sorted array of post objects by number of upvotes. In the snapshot for single event listener, first check the timestamp to see if it is within the last 24 hours. Next, if the array has a count of less than 15, add your post in sorted position (using an appropriate parsing method). If it already has 15, you'll need to see if the minimum lowest element in the array has more upvotes. If it does not, you'll need to find a place in the array to replace. After you are done parsing through every snapshot from Geofire, you will have your array of posts from the last 24 hours, sorted by upvotes.
I've a simple chat in swift and I retrieve 10 elements with queryLimitedToLast.
I want retrieve more element with a refresh function. How can increase the number of elements?
I've try to set the value in queryLimitedToLast with a variable but don't works.
Thanks!
Firebase Queries are immutable; once you've created them, you cannot modify them.
So you'll have to create a new query, which starts at the end of the previous query.
I am successfully able to read and print the contents of a text file. My text file contains 5 data entries such as
Rashmi 120
Prema 900
It must sort only the integers in descending order and swap the respective names attached to them. the first column of serial number must remain the same. Each time a new entry is made that score must be compared to the existing 5 records and placed accordingly with new name and score.
Since this is blackberry programming and blackberry APIs don't support Collections.sort,please tell me how do I do this. I tried using SimpleSortingVector but I am unable to put it into coding form.
i believe u need to start with your own logic like
1) sorting depends on comparison
2) before making any comparison u need to split each string by spaces
3) after splitting save the name and numbers in different arrays
4) compare the numbers and accordingly do sorting
5) after this merge the array contents using indexing
m just giving u a way may be its not the perfect but drilling down may refine logics and usage of the api