My firebase DB looks like
Now I want to query the database such that I take all the users whose email id is in a query list.
For example in the above shown database structure, if I want to make a query such that find the users where username in ["allen20252482", "arne19712450"] which can give me two users.
Is it possible?
Currently I can query like https://xyz.firebaseio.com/users.json to get the complete user node data , But is it possible to filter like where I take only those users whose username is in the given query list?
I am using REST API endpoint to query the Firebase DB.
Any suggestion is very much appreciated
I suggest reading the documentation on filtering data. It sounds like you want to filter by a child key:
https://xyz.firebaseio.com/users.json?orderBy="username"&equalTo="abcdef"
You will only be able to specify one username at a time.
Related
I have problem with restructurizing my database.
So far I have different users storing measurement data. Keys are made of (userId+currentDate). But now I'd like to add sharing this data between users.
Users can send requests for permission to view each other data, but I don't really know where should I store this data.Should I add additional key(userId) with value (true) inside each node? Can I even update the database in such way - "If user1 is friend with user2, add user1:true to each of users2's nodes"?
How should I proceed?
You can create a second type of node, something like shared_with_me_<my_user_id> for the user requesting access to another user data. If agreed by him, you insert this user_id to that node (like <other_user_id>:true) so you can query it later.
That said, I really suggest that you start using the Cloud Firestore Database.
I have a Firebase database with a list of users and a list of best friends,
a user's best friends can be pulled by using it's userid:
users list:
userid
user data
userid
user data
..
best friends list:
userid
userid of friend
userid of friend
...
userid
userid of friend
userid of friend
...
...
...
Is there a way using the Firebase api to get the friend's data in a list instead of a list of userid's of your friends when making the call to get your best friends ? Now i have to do 2 steps (get best friends id's -> loop users for friend's data)
No, there is not. There is no way to achieve this. You need to query your data twice, first time to get best friends id's and second to get the actual data of those friends. You cannot get that list in a single step, using a single query..
What I think from your description is that you want to perform a join.
There's no official "join" method in the Firebase Database SDK, but
you can use multiple listeners to combine data from multiple paths.
https://www.youtube.com/watch?v=Idu9EJPSxiY
check out this youtube video it will help
I want my Firebase Database to be sorted right at the moment a new variable enters.
My goal is to sort an integer representing the subscriber ammount from biggest to lowest, so that when I populate my recyclerview (Top subscribed account) I don't have to check against every value in my Database.
Is there a way of doing something like that, or a way better solution to my problem?
The Firebase database sort all the childs using alphabetical order. So using only the Firebase reference, you always get yours "Top subscribed accounts" in the alphabetical order of his Ids.
Firebase provide helpful methods to filter or order your querys. Check firebase.database.Reference especially the method orderByChild
Making querys with the correct filtering (order), it's the way to get the Firebase data in the way you want.
I'm new to Parse.com and was having trouble designing the structure of my database, and how to retrieve the desired data.
In the database, each user (primary identifier as email) has a list of friends and a status boolean. The friend list contains the email of other users in the database. I need to get the status boolean for each of the friends in a particular users list, and preferably in a single query to the server.
What would be a good way to design our structure and retrieve this data. Currently, I made two data classes (tables), one containing each user with their boolean status, and another containing each user and their list of friends. Firstly I was not sure if this structure is the correct way to go. Secondly, I don't know how to retrieve the status boolean for each user in a single users friend list.
Edit I actually discovered the relation column type just yesterday, but I was unable to figure out how to use it. 1) How do I link a Persona to a User in code? I understand I need to use ObjectID here, but how?
2) How do I add other Personae (friends) to a relation of a single Persona (the user). I was unable to populate this relation column. I understand query can be used on the relation column, but I couldn't reach that far ahead without populating the relation column.
3) In my query to the server, am I pulling the entire table? Lets say a user has 2 friends. Is there a way for me to fetch only the current user, and the two friends, or am I pulling the entire table, and then doing my filtering on it. I am concerned with the network being burdened if my table of users grows big.
Edit Well I couldn't figure out relational queries perfectly just yet, however, I found a good solution to my problem. Since the list of friends changes very rarely, I'll be maintaining this list offline, resulting in a single query to the server of pulling in the status of my friends. Along with this list, I may or may not also decide to pull in my own data and get an updated friend list. Thank you for your help though.
The way to model many-to-many relations in parse is with the relation column type. This is the best choice to describe how a user has many friends who are users. If this is a social-network-like app, another good bit of advice is to create a class -- distinct from the parse User -- that describes users' public personae.
This is so you can have the parse User class remain as the private, customer relationship between your app and a real person (there are built in security constraints here). This other table, say we call it Persona, can have a pointer-typed column to its user, keep such things as nickname, profile image, etc. and also keep your boolean status.
_User class - default stuff that comes standard with parse, plus anything pertaining to the customer relationship with your app.
Persona - pointer to _User table, boolean status, other public info, relation called "friends" relating this to other Persona.
So, given a logged in user and his/her currently selected persona (your choice whether users may have more than one personae), you can get friends' personae as follows (in pseudo code):
friendsRelation <- myPersona.friends
friendsQuery <- friendsRelation.query // query is a method on relation
run friendsQuery asynch, then the result will be allFriendsPersonae
for each persona in allFriendsPersonae
status <- persona.status
If you choose not to take the persona class advice, the "code" above is the same, just replace persona with user.
Edit - in response to question edit:
1) Link a persona the user by setting the persona's user column (pointer type) to the user object. To get that persona later, when you only have a user, query the persona table where "user" column equals user.
2) Relation implements an add() method. If you have a personaA, and want to add personaB as a friend, you getRelation("friends") on personaA, and send it add(personaB).
3) The query you get from a relation is a query only for members of that relation. So if personaA has two friends personaB and personaC, you'll get only B and C when you run personaA's friends query.
Am fetching list of users for my listview (android) i used firebaselistadapter to backing up my listview , I wanna show users data except mine .
Like an sql query Select something from usertable where id!=userid;
i wanna fetch all other users data,
Firebase currently only offers a way to include nodes based on the presence of a certain value. You cannot exclude nodes based on the presence of a value.
Update (20160828): I wrote a related answer today that shows how to detect the absence of a property.
I have the same issue, using angularfire and geofire I am searching for business prospects within a radius and trying to create a lead only for new prospects, that means to exclude any existing account already with an existing relation. To do so I need to open a firebaseObject for each key returned by geofire and after $loaded() , check for _.isNull(loadedFirebaseObject.$value). The lodash function _.isNull() returns null if the firebaseObject path does not exists (a prospect) or undefined if it exists (not a prospect but an existing account).
Is there a better way of doing this?