I work with firebase database, I have the following data,
I need to get all groups names (GName) of a user by his phoneNum, i.e. all groups of specific user, How can I get that in swift 4?
You should consider restructuring your data. If a user belongs to more than one group in your application then you'll probably have to duplicate your user node for every group the user belongs to in your data structure. You can create another JSON object that holds all of the groups that a user belongs to. Here is a sample JSON for you:
{
"users": [{
"xyz123": {
"userId": "xyz123",
"username": "user1",
"phoneNum": "123456",
"groups": [{
"groupId": 1,
"groupName": "aaa"
}, {
"groupId": 2,
"groupName": "bbb"
}]
}
}]
}
As for filtering with the phone number, you can get all users inside a list and filter the result with the phone number criteria
result = result.filter({item.phoneNum == "123456"})
or get phone number of the user to a upper level, call .child() method with the phone number criteria and fetch the specific user.
Also take a look at structuring data part at firebase documentation.
https://firebase.google.com/docs/database/ios/structure-data
Hope that helps.
Related
Recently I work on a store website where users could order from mobile applications and the admin could search over user data in the admin dashboard, I use elastic search as a search engine in my rails apps. Store admin could create custom queries and retrieve their custom results, for each user who orders by the mobile app I create two custom indexes and insert them on elastic. these indexes are user profile data and user events. In profile User profile collected like first name, last name... and in the event, I collect user actions like login sign up...Users in the mobile app could update him/her profile so each time I have to create a profile index and insert it in my elastics. I have a problem, assume a user-created profile with this informations:
profile-2022-05-29
{
"event": "sign_up",
"profile_id": 1,
"profile": {
"id": 1,
"first_name": "helen"
}
}
and next day update her profile with new data like this:
profile_2022-05-30
{
"event": "sign_up",
"profile_id": 1,
"profile": {
"id": 1,
"first_name": "rose",
"last_name": "brown"
}
}
So I have two different profile indexes in my elastic for one user now if I want to find a user the last name is "brown" and have the event "sign_up" Elastic only returns the last index "profile-2022-05-30" document, that is the user profile with updated information but I expect that elastic return both indexes document because the user updates her profile so I have two indexes for one user.
Does anyone could help me what is the best query DSL in elastic that returns both indexes.
this is my elastic query:
GET profile_*/_search
{
"query": {
"bool": {
"must": [
{
"match_phrase": {
"last_name": "brown"
}
},
{
"match_phrase": {
"event": "app_open"
}
}
]
}
}
}
Updated: Each time I want to query over my data I search over all of my indexes like this:
Get profile_*
{
"some query"
}
I am working on a Zapier integration for an online form builder. Each unique form for our users has lots of long, auto-generated field names.
We have a trigger called “New form entries”, which polls our server for form entries, and comes back like this:
[
{
"id": "6209aee326baa600224d822c",
"email_907058157108782": "test#test.com",
"phone_589083232390193": "12345",
},
{
"id": "61fd629f19408200225e1893",
"email_907058157108782": "test#test2.com",
"phone_589083232390193": "54321",
},
]
However, this results in end users seeing these really long, gross field names in the Zapier interface:
My question: how do I get Zapier to display friendly labels to the user, whilst using the unique field IDs behind the scenes?
I’m thinking of returning something like the following (each object represents a form entry, , but I need to know how to actually use “friendlyFieldName” and “value” in Zapier!-
[
{
// the id for the entry
"id": "62179ec5ab9daa0022df7d1d",
// the id for the first field entry
"text_576692390099896": {
// a friendly name and value for zapier
"friendlyFieldName": "What is your favourite colour?",
"value": "Blue"
}
}
]
Thank you :)
You can define output fields labels in outputFields. Here are the reference document that you can follow: Output Fields
I am working on an OData v4 compliant RESTful API, and have a need to filter a collection of tasks based on the assigned user. It would be useful to be able to handle this based on the active user, without having to explicitly refer to the user ID of the assigned user in the filter expression. Take the following request and response as an example:
GET /Tasks
{
"value": [
{
"Assignee": "user1"
},
{
"Assignee": "user2"
},
{
"Assignee": "user3"
}
]
}
I could do something like /Tasks?$filter=Assignee eq 'user1' but this requires that the consumer keep track of who the active user is. Is there some convention to do this in a more generic way? For example: /Tasks?$filter=Assignee eq $ActiveUser.
I have been able to retrieve event details using
#graph = Koala::Facebook::API.new(access_token)
#eventSummary = #graph.get_object(eventId)
and getting users list invited using
#eventSummary = #graph.get_connections(eventId, "invited")
I want to get count for all user invited, maybe, Declined and accepted for the event. for which i'm using
#eventSummary = #graph.get_connections(eventId, "invited?summary=1")
which again giving me the list of users only. when used graph.facebook like
https://graph.facebook.com/***eventId***/invited?access_token=*****access_token****&summary=1
i'm getting the count in result.
{
"data": [
{
"name": "xyz",
"rsvp_status": "attending",
"id": "10000000123"
}
],
"paging": {
"next": "https://graph.facebook.com/***eventId***/invited?summary=1&access_token=***accesstoken***&limit=5000&offset=5000&__after_id=100004389574321"
},
"summary": {
"noreply_count": 0,
"maybe_count": 0,
"declined_count": 0,
"attending_count": 1,
"count": 1
}
}
for just solving purpose i'm getting result using fql, as:
#eventSummary = #graph.get_object("fql", :q => "SELECT all_members_count, attending_count, declined_count, not_replied_count, unsure_count FROM event WHERE eid = #{eventId}")
But this is not convenient to use.
Can anyone please help, what am i doing wrong ? To get Event RSVP counts.
I'm using rails v.3.2, for facebook using Koala gem.
Thanks in advance.
I've seen it too, that when you request the event itself, those attendee count fields aren't included. You can use the second parameter to specifically ask for them though:
#eventSummary = #graph.get_object(eventId)
#eventSummary.merge(#graph.get_object(eventId, fields: "attending_count,declined_count,interested_count"))
The first call gets your "standard" event details, something like this:
{"description"=>"Blah blah blah",
"name"=>"My Event Will Rock",
"place"=>{"name"=>"Venue Bar",
"location"=>{"city"=>"Citytown",
"country"=>"United States",
"latitude"=>43.05308,
"longitude"=>-87.89614,
"state"=>"WI",
"street"=>"1216 E Brady St",
"zip"=>"53202"},
"id"=>"260257960731155"},
"start_time"=>"2016-04-22T21:00:00-0500",
"id"=>"1018506428220311"}
The second call gets just those "additional" requested fields:
{"attending_count"=>3,
"declined_count"=>0,
"interested_count"=>12,
"id"=>"1018506428220311"}
You can store them in separate variables, or as I'm suggesting above, use the hash#merge method. (There shouldn't be any problematic overlap between the keys of these two hashes.)
Alternatively, you can get all these details in one request by explicitly requesting everything you want.
I have some data like so in elasticsearch:
account (http://localhost:9200/myapp/account/1)
========
name
state
groups //groups is an array containing objects like so {id: 1, starred: true}
//the id is the id of the group type
email (http://localhost:9200/myapp/email/1?parent=1)
========
email
primary //just a boolean to denote whether this email is primary or not
group
========
name
description
emails are children of account.
Based on imotov's excellent answer, I am able to run a search on account.name and email.email and return ALL accounts where the searched prefix matches the above 2 fields:
{
"query": {
"bool": {
"must": [
{
"term": {
"statuses": "active"
}
}
],
"should": [
{
"prefix": {
"name": "a"
}
},
{
"has_child": {
"type": "email",
"query": {
"prefix": {
"email": "a"
}
}
}
}
],
"minimum_number_should_match" : 1
}
}
}
What I would like to do now is to return 2 custom fields for each result:
For each result return a field called email, if the search was matched on the email type (which is a child of account), return that email, otherwise return the primary email linked to the account, if none, null can be returned.
For each result return a field called group. The value of the field should contain the name of the starred group whose id is stored in the groups array. Essentially: Find group.id where group.starred is true in each account.groups, then return the matching group.name from the group type base on the id we found.
I have been looking at script fields, but I am not sure if it is able to return fields for each hit. I am also not sure if the above is actually accomplishable in ES.
Could someone provide some pointers as to whether this is possible and how to get started?
Currently, there is simply no way to get to access the data in a has_child or nested clause.
The only solution is to get some data, make some decisions on the client and then get more data.
Here's what I did to achieve it:
Run the query above and get back the data.
To deal with showing the match emails or the primary email (run on the email type):
{"query":
{"bool":{
"should":{
{
"prefix":{
"email" : "the query"
}
},
{
"terms":{
"_parent" : ["list", "of", "account", "ids"]
}
}
}
}
}
}
Base on the above query, we can get any email addresses that were matched by the search term. Remember to set the fields in the above query to include _parent.
We can then use array_diff() or a similiar function in languages other than PHP to diff the parent ids from above and and original query. This should then give us a list of accounts where no email was matched. Simply then send another request to get the primary emails for those accounts.
For the groups, send a query to type account and:
Constrain _id to the list of account ids.
Constrain group.starred to true.
This should get you a list of starred groups. To get more information (name etc), send a query to type group and:
Constrain _id to the group ids above.
Finally, do some client side processing to put it together so that it is easier for the next part of your program to use.