Im trying to check the emails of my users in my firebase database, if their email already exists. My json looks like that:
I dont know how to get the full path to email, because every User starts with the Unique Identifier and I dont have that information. Is it possible to use a wildcard /users/*/email or something like that?
this.afdb.database.ref('users/*/email').orderByChild('email').on('value', (snapshot)=>{
console.log(snapshot);
});
When a Firebase Database query runs against a location, it considers each child node under that location. And for each child node you can test the value of properties at a known path under that child.
There is no support for wildcards, nor does one seem needed for your case here:
this.afdb.database.ref('users').orderByChild('email').equalTo("pqoo#poam.com").on('value', (snapshot)=>{
snapshot.forEach((child) => {
console.log(child.val());
});
});
So the two changes are:
We query location users order by email and only return nodes with value pqoo#poam.com.
There will potentially be multiple results. So the snapshot contains a list of those results. Even if there is only a single result, the snapshot will contain a list of one result. So we use snapshot.forEach(...) to loop over the results.
Related
Is the following composite where(in:) and where(isEqualTo:) query possible in Firebase Firestore?
(Swift)
let taskDocIds = ["0ArJnMgTfDkvolUcZR8E", "0cdcZsfaEJQpsiByJIgH"]
return db.collection("tasks")
.whereField("status", isEqualTo: "approved")
.whereField(Firebase.FieldPath.documentID(), in: taskDocIds)
.limit(to: 100)
.getDocuments(as: TaskModel.self)
My security rules enforce that only tasks with status as approved may be read. However the the query above results in an error (see below) when the status of any of the tasks whose id is in the taskDocIds array has a status other than approved.
Error: Domain=FIRFirestoreErrorDomain Code=7 "Missing or insufficient permissions."
If the query is possible, does a composite index need to be created? And if so, how does one go about configuring that manually (using Firebase Console) for a FieldPath document id?
Permission errors can never be resolved by adding an index.
The problem is that the rule doesn't know if your entire set of taskDocIds would be allowed without checking them all individually. Firebase security rules are not filters, so, when performing a query, the rule will not read and check each document individually and give you only the ones that match. Without assurance that every document that could match the query absolutely does match the query, it simply fails the entire rule.
Your alternative is to simply getDocument() each one individually. With individual document gets, the rule will check the individual fields of the document.
I'm trying to fetch details from VSTS using VSTS query API. So to get all Portfolio Epics I created a custom query and used its ID to get that in JSON format. the query looks like this
https://dev.azure.com/{organization}/{project}/{team}/_apis/wit/wiql/{id}?api-version=5.0-preview.2
But the issue is its not giving me many details about each of the work items in JSON. It only lists the ID and URL. Like this
WorkItems:[
{ID:234,URL:"workitemurl"},
{ID:235,URL:"workitemurl"},
{ID:236,URL:"workitemurl"},
...
]
So if I need more details about an item I need to execute those individual URl for each PE and thus I can get its details. instead of I am just checking is there is any way of getting an ID (keyedinID of each work item along with the ID and URL) like this. Please note KID is a field if we execute the URL separately. So to avoid that extra process, I would like to get that along with the WorkItems.
WorkItems:[
{ID:234,URL:"workitemurl",KID:002},
{ID:235,URL:"workitemurl",KID:023},
{ID:236,URL:"workitemurl",KID:033},
...
]
So how can we make this possible?
The Web UI uses a different API to get query results (/_api/_wit/_query), which allows query+data in a single pass. This is an old __v5 type call, which means it's considered internal.
The proper way to do this now is to first do the query as you're doing it right now and then call /_api/wit/workitems?ids=1,2,3,4 using the IDs from the references you got from the first call. That will also allow you to load the details dynamically and in small batches which will result in a more responsive UI.
See:
https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work%20items/list?view=azure-devops-rest-4.1
I'm having a bit of a problem with trying to access the same contact between multiple devices. My goal is to have a user select a contact and select a phone number and email address, which will then be stored in a database. If the user opens the app on another device, I would like to have the same contact selected.
I was hoping to use the CNContact.identifier for this case, but it appears that it is a device specific id. I could store the identifier for each device, but that would require the user matching contacts and that doesn't seam ideal.
This doesn't seam like it should be difficult but apparently I'm missing something. Thoughts?
The solution that seams to working for me is, I store the Contact identifiers, Address identifiers, Contact name, and the Address in my database. Then I take a mutli-step appoarch.
Search for Contact:
I attempt to find the contact based on the stored contact.identifiers I have already saved.
If I find 1 contact (identifier matched) => Great! I then attempt to match the found contact to my address.identifiers. Once again, if I find only 1 match, we're great! If not I then go to attempt to find an address (See below)
If I find no contacts (no identifiers matched) => I attempt to find the contact based on the Contact Name I had saved previously. If I do find a match, I then go to attempt to find the matching address (see below).
Search for Address:
Since at this point, I have a CNContact record that I believe matches, I look at each of their postalAddresses and compare it against the Street/city/state/zipcode/country that I have stored in my database.
If we find that perfect match, then I update my identifiers to include the new address/contact identifiers
If we ultimately don't find a match, I give the user an option to manually select the contact/address from their device.
I'm using Microsoft Graph to get a list of messages for a user.
I'm using the following URL
https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages
One important thing that is returned by this is the meetingMessageType when the message revolves around a meeting request.
I would also like to get the uniqueBody of the message. However, that's not provided by default. One needs to specifically ask for that field. I can do that by adding ?$select=uniqueBody to the URL.
However, that now means that I need to add the rest of the fields I want to the $select query parameter. That's not a big deal until I run into meetingMessageType. Microsoft Graph returns:
Could not find a property named 'meetingMessageType' on type 'Microsoft.OutlookServices.Message'.
What can I do to ensure I get both uniqueBody and meetingMessageType?
Try this:
$select=uniqueBody, microsoft.graph.eventMessage/meetingMessageType
Yogesh's answer is close but will result in a Only one level select is supported error.
As long as you don't care about the value of meetingMessageType, you can use this select:
$select=microsoft.graph.eventMessage, uniqueBody
You'll note that the results no longer include meetingMessageType as a property. The list however is limited to only those messages that are eventMessage, effectively giving you a result set filtered to only show meeting requests.
I am trying to figure out a way to get a list of each unique child in my Firebase Database & get a count of each unique child.
So for example if somebody entered Amazon 5 times an Hulu 2 times. I want to be able to know that. However, I don't want the user to know this.
I had a few ideas on how to do this.
Idea 1
Use Firebase's:
Answers.logCustomEvent...
However, I see two flaws with this idea.
Flaw 1: This wouldn't be useful for data that has already been entered.
Flaw 2: A user could enter Amason on accident and then changes it later to be the correct Amazon. I would get the incorrect entry..I could log changes but then I'd get bad data...or at least confusing data.
Idea 2
I could write a function inside of the app that could do this, but like I said. I don't need this functionality in the app for the user. I want it so I can know which sites I need to add functionality for first over ones that are seldom entered.
However, is it possible to have 2 apps that use the same database? So the main app is able to read and write data. While I could create a simple app that I wouldn't publish, only really use for myself that could Read the data but not write to it...
I tried to make my Database flat as I knew how..
When a user adds a service it doesn't go under the user node, I have a child called "services" and I just reference that service child in the "user" child.
So my database looks like this
cards
card uid 1
cardname: ""
services
service uid 1: true
services
service uid 1
serviceName: Amazon
serviceUrl: ""
service uid 2
serviceName: Amazon
users
... reference the card this user has access to
So to repeat the question.
I want to be able to know each unique serviceName and if there are duplicates of the same one..how many there are..
I don't need to know who created it or when..
you may have another table where you have objects with only 2 fields: serviceName and count.
So, everytime you have a new instance, you check if it already persists in your table and increment the count value, otherwise create a new row.
Users will not see that info.
And, yes, you can access one database from several apps. Just get clientID, trackingID, etc...