how to filter Collection (Firebase) by uid in swift - swift

I'm having problems trying to get one specific value from Firebase.
I'm using .whereField('uid', isEqualsTo: "givenID") in Collection("something") but I'm not getting any response. I know in Flutter the field is 'uid' but for some reason in swift isn't the same. I'll appreciate your help maybe with the name of the field or another way to bring the value with the given id in Firebase.
Useful information
Swift 5
XCODE 11.4.1

I found a "solution". Create a field in my Collection called "id" and assigning it with the same id from the document. Now I can just
db.collection("yourCollection").whereField("id", isEqualsTo: "givenID").
Not the best solution, but a solution is a solution.
UPDATE
I found it.
db.Collection("yourCollection").document("GivenID")
This bright you the subCollection
And that's all

Related

Get Firebase Auto-ID column in FlutterFlow

Reviewing one of my Firebase schemas I can see that I have a couple of columns, but the auto-generated ID column does not show up:
However, when clicking on "Manage Content" the ID column can be seen:
The problem I have is that in other collections I make a reference to this collection by this ID, however, it doesn't pop-up in FlutterFlow to filter on:
Question: Is it possible to get the Auto-ID column in FlutterFlow?
As far as I know that is unfortunately not possible.
You could solve this by adding a column CopyOfId to your scheme.
You could then write a Firebase Function that triggers when you create a new document (https://firebase.google.com/docs/reference/functions/firebase-functions.firestore.documentbuilder.md?authuser=0#firestoredocumentbuilderoncreate). You could make this function copy the contents of the ID column to your own CopyOfId, making it accessible in FlutterFlow.
A deeper question is maybe for what use case you want this behaviour: why would you need to filter on an autogenerated ID that you do not know the value of - and that you can't access - in FlutterFlow? If we know your use case, there is probably another way to achieve what you want to achieve.

MongoDB Compass throws error: Update not permitted

I am taking online class by MongoDB uni. and using a test free tier cluster. I have created a very simple collection with basic fields. Creation was successful. 5 documents. Each document has basic 8 fields as can be seen in the screenshot. The problem I am facing is I am getting error while inserting a new field called 'Number of Children(0-12 yrs)' with data type int32. This error occurring when I user data type as in32, int64, decimal128, double so far. It does not show up for string and a few other types. Being a beginner, I am not able to find more info on this error, please help.enter image description here
That looks like a bug. You can work around by entering your value as the string value and then converting it to the appropriate type.
I have filed a ticket with the Compass team. See https://jira.mongodb.org/browse/COMPASS-4300

Clio API - What is the correct format to Update (PATCH) a custom field value for a matter

Anyone been able to successfully update the custom_field_values for a matter via Clio's API?
I'm trying to update the value for custom_field_values under a single matter. I'm able to send a JSON string using PATCH and update the default values for a matter like location or description using the following format
{"data":{"location":"Orange"}}
But when it comes to updating a "custom field value" I'm getting a 422 Unprocessable Entity error. I'm following Clio's v4 API Documentation and my understanding is that to update a custom_field_value you need the following JSON:
{"data":{"custom_field_values":[{"id":658213,"custom_field":{"id":139385},"value":"New Value Goes Here!"}]}}
However here is the message coming with the 422 error:
{"error":{"type":"ArgumentError","message":"An invalid argument was supplied: invalid custom field value id provided, acceptable format is <type>-<unique id>"}}
I can't interpret the part suggesting the acceptable format!
I've also tried sending the JSON in the following format which is closest to Clio's V2 API Docs for updating a custom field:
{"data":{"custom_field_values":[{"custom_field":{"id":139385},"value":"New value goes here"}]}}
But then this is what I get back:
{"error":{"type":"ArgumentError","message":"An invalid argument was supplied: custom field value for custom field 139385 already exists"}}
Please note that this is being tested in POSTMAN regardless of my development environment. I appreciate your response!
I've successfully created queries to update custom field values in matters many times, and these run all the time for me. I've compared your json to some examples of the json I'm successfully sending. Your syntax appears correct, but there's enough missing for me to only guess at where your mistake might be.
First, you're sending a PATCH to https://app.clio.com/api/v4/matters/{matter id}.json right? It took me a while to learn that you can't update the value of a matter's custom field with a query to https://app.clio.com/api/v4/custom_fields/{id}.json.
Second, just to clarify, the 658213 id you used above (the first id field) should be the unique id of this instance of your custom field. You won't get this until you've created an instance of the custom field particular to this matter. The second id field, where you've put 139385 is the id for the custom field itself, which you could get with a query to https://app.clio.com/api/v4/custom_fields.json.
If you're looking in the V.4 docs under Custom Fields, you won't find this, or at least I didn't. BUT you can find it in the intro section to the Matters portion fo the documentation: https://app.clio.com/api/v4/documentation#tag/Matters
Hope this helps. I'd imagine someone at Clio could help by verifying your error string is delivered when you have an incorrect custom field value unique id.
To further clarify Jacob's answer for everyone else:
custom_field{id} is the id given to a custom_field when it's created and will be the same for all matters or contacts it's used in.
custom_field_value{id} is the id given to an instance of the custom_field added to a particular matter and unique only to that matter
To add a custom_field to a matter for the first time the following format is used:
{"data":{"custom_field_values":[{"custom_field":{"id":123456},"value":"string or integer depending on the type of CF"}]}}
To update a custom field already added to a matter the following format should be used:
{"data":{"custom_field_values":[{"id":"text_line-1234567", "custom_field":{"id":123456},"value":"string or integer depending on the type of CF"}]}}
To delete a custom field already added to a matter the following JSON format is sufficient:
{"data":{"custom_field_values":[{"id":"text_line-1234567", "custom_field":{"id":123456},"_destroy":true}]}}
Format for updating a custom field already added to a matter:
{"data":{"custom_field_values":[{"id":"unique_instance_of_your_custom_field", "custom_field":{"id":'custom_field_id'},"value":"value which should be updated"}]}}
Here, the first id field should be the unique id of this instance of your custom field. To get this value follow this documentation section, app.clio.com/api/v4/documentation#tag/Matters and the second id field is the id for the custom field itself.

How to set more than one value to a child in Firebase using Swift?

I am trying to make a money related app which shows the user their spendings as a project to get used to Firebase. So I stumbled upon this issue; I can't seem to figure out how to add more than one expense assigned to a user. Whenever I add a new expense, the existing value in Firebase gets reset to the new value but I want it to store both the new and the old value. How can I do this?
There's something called "autoID" if that helps. I'll link that in a few moments.
Edit: It's used here.
childByAutoId() is what you want for swift. See Updating Or Deleting specific data section in the Read and Write Data on iOS
let thisUserRef = ref.child("users").child(users uid)
let expenseRef = thisUserRef.child("expenses").childByAutoId()
let dict = ["expense_type": "travel", "expense_amt": "1.99"]
expenseRef.setValue(dict)
will results in
users
uid_0
-Y88jn90skda //<- the node key created with childByAutoId
expense_type: "travel"
expense_amt: "1.99"
the childByAutoId is super powerful and allows 'random' node keys to be generated that contain your child data.
See the answer to this question and this other question for some tips on data modeling and queries.

How to make a field "autocomplete"?

I can't figure out how to make a field autocomplete in ATK.
I guess it has something to do with the type "reference" but still not sure.
Suppose I'm looking for a client name in a "line" type field, then the autocomplete should list me all/topXX matching names.
Scenario 1:
Once I hit [Enter] I'd need all that row from DB loaded in a form fields so I can edit the record.
I guess this requires getting the client ID first then posting to an "edit" page then calling "loadData()" method for that ID and populate fields.
Scenario 2:
I'm assignig a job request to a client. First I find the client then I could store its ID in a hidden field to be posted then.
Any advice?
TIA
I would suggest you to go with 2 forms. First form with a single field, and when field is changed it automatically reloads second form including the parameter.
You will also need an autocomplete field. Autocomplete is somewhat buggy in 4.0, but it have been polished up in 4.1 by using a technique in http://jqueryui.com/demos/autocomplete/#combobox
For use with models and controllers and also dropdown, example is here:
http://codepad.agiletoolkit.org/reloadform
Alternative example:
http://demo.atk4.com/demo.html?t=22
Since 4.1, you can also use autocomplete fields instead of reference:
$form1->addField('autocomplete','user');