i have store the multiple user in database and want to retrieve only the one user data in ionic app..e.g
{ "users": { "user 1":{ "name": "jeff" }, "user 2":{ "name": "Ali" } } "user_meta"{ "user1":{ "Data": "more data on the stock price" }, "user2":{ "Data": "lolz" } } }
data structure look like this the user1 get only theri name and metadata associate with them ... like this.."user1":{
"name": "jeff",
"meta" : {
"user_meta": "more data on the stock price"
}
}
this.projects =af.database.list('/users').map((items) => {
console.log(items);
return items.map(item => {
item.metadata = af.database.object('/user_meta/' + item.$key);
console.log(this.one);
return item;
});
});
this code retrun me all the users and theri meta data ...
<ion-card *ngFor="let item of projects | async"> <ion-card-header> {{item.name}} </ion-card-header> <ion-card-content> {{(item.metadata | async)?.moreData}} </ion-card-content> </ion-card>
any one help me to get only the one user data per app... the specific user get only their own record... :)
I think You need To use Filter Method maybe ..
@davideast #askforfirebase
Have you tried querying the list of users? If you have users in your database:
// Firebase
{
users: {
-KAbCDe_FireBase-KeY_1: {
uid: '9876abcd', // some unique user id
name: 'Jim',
meta: {...}
},
-KAbCDe_FireBase-KeY_2: {
uid: '1234jklm', // some unique user id
name: 'Jane',
meta: {...}
}
}
}
You can query the list using the user id (or some other key of your choosing) like this:
import { Subject } from 'rxjs/Subject';
const userId$ = new Subject<string>();
const userQuery$ = af.database.list('/users', {query: {
orderByChild: 'uid',
equalTo: userId$
}});
userQuery$.subscribe(users => console.log(users)); //=> [{name: 'Jim' ... }]
// submit a query using user id
userId$.next('9876abcd');
Alternatively, if your users are required to sign in, and you store them using an auth id:
// Firebase
{
users: {
[authentication id]: {
name: 'Jim',
meta: {...}
}
}
af.database.object(`/users/${auth.id}`)
.subscribe(user => console.log(user)); //=> {name: 'Jim' ... }
@r-park Hi, I have a question. Is It possible to remove the object containing the query you have made? Or if you do a query for example by name and then you will delete all the objects containing that query you just make?
@r-park thanks ...1st one work for me
but one problem the data associated with specific user display in console but not in view ...
but adding aa button and call the function
filterBy() {
this.userSubject.next("[email protected]");
}
will display immediately..
one other thing console show me warming,,,
FIREBASE WARNING: Using an unspecified index. Consider adding ".indexOn": "user" at /textItems to your security rules for better performance
Try using ReplaySubject instead of Subject
import { ReplaySubject } from 'rxjs/ReplaySubject';
const userSubject = new ReplaySubject(1);
userSubject.next('[email protected]');
For the FIREBASE WARNING — check out the docs on indexing your data
uu rockkk thnks alotttttt