angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Query with partial value

Open joyceview opened this issue 10 years ago • 8 comments

Hi there,

The query function can get us when the value in Firebase is equalTo a certain value. But what if I want to get "contains", instead of "equalTo"?

My case is,

"data1" : { 
"repeatDays" :  "Mon,Tue,Wed,Thu" 
}

When today is "Mon", which is apart of value for key 'repeatDays', I want to be able to get the data1 node.

How can I do this?

Thanks a lot!

joyceview avatar Aug 13 '16 03:08 joyceview

There is no such thing and no straight answer to this, look below two links, may be you get your answer: http://stackoverflow.com/questions/28589092/firebase-query-find-item-with-child-that-contains-string http://stackoverflow.com/questions/22506531/how-to-perform-sql-like-operation-on-firebase

amity203 avatar Aug 14 '16 05:08 amity203

Thank you for your reply. Looks like it's quite complicated.

Can we use functional programming for this case? Add map, filters at the page when we get the data from the service, which returning a list of FirebaseListObservables?

Or, maybe I'll need to restructure my data.

joyceview avatar Aug 16 '16 08:08 joyceview

Yes you can use all your programming skills to manipulate data once you get from firebase. Also, as per me structuring data in firebase is foremost key to get an effective solution if you think that data will grow with time in significant way.

amity203 avatar Aug 16 '16 09:08 amity203

Right now there is no "contain" operator included in the firebase service. It would be difficult to include something like *bar to search for Foobar, because *bar could be a normal value inside your database.

So you can load everything to your client and filter it there. I don't recommend it because all of your clients have to get it for a search.

Better implement a service on a server, that does the search for every user. In this way it's just a bit complicated to say which query belongs to a user.

cre8 avatar Aug 18 '16 06:08 cre8

@cre8 How to implement a service on a server? Right now my project is built on top of: Ionic2 + AngularFire2, with Angular2 and Firebase3 as the backend database. How to implement server side service?

Sorry I'm very new to this structure, I'm afraid this is a too big topic.

joyceview avatar Aug 18 '16 06:08 joyceview

I don't mean an angular service, but a something that is doing the Jop for you and not the client.

You can set up a node server and include the firebase sdk. There is a good example in the official dokumentaton. Then you can program a listener for a value, where the user inserts the search query. Your program will iterate over all entries and will write the one that matches inside a node. The client is listening to this node and will only get the results that are relevant for him and not all values from the database.

https://github.com/firebase/flashlight/blob/master/README.md seems to be good to look at.

cre8 avatar Aug 18 '16 10:08 cre8

Thank you for the information. I didn't know we can do this. I'm still not very clear about how this relate/impact to AngularFire, but definitely worth to check out.

Thanks again!

joyceview avatar Aug 18 '16 17:08 joyceview

you can try this in: query: { orderByChild: 'merchantName', //your field name of realtime database // equalTo: this.gettermconvar, startAt: this.gettermconvar, //var of onclick endAt: this.gettermconvar+"\uf8ff"

		}

tiokadams20 avatar Feb 26 '18 04:02 tiokadams20