Query a node which is an array itself
Hi there,
Is there a way to query a node which is an array? What I want is return this node of "-KO8cSA1a6Tl21vHJao5" when today is Monday or Tuesday.
"data" : { "-KO8cSA1a6Tl21vHJao5" : { "repeatDays" : [ "Mon", "Tue" ], "updatedOn" : "Mon Aug 01 2016 22:06:12 GMT-0700 (PDT)" } }
I also tried to save the value as a string instead of string[], but can't get the result either.
Could anyone help me with this?
Thanks a lot!
You mean, you want to get the nodes that has a repeatDays of Mon && Tue ?
Yes, If today is Mon or Tue, I want to get the node.
You can refer to this issue #396
I'm using the filter. The filter is working only if the value in firebase is a string. But not working if the value is an array, nor as a string like "Mon,Tue". As my today's variable could only be "Mon" or "Tue", but my RepeatDays in database could be up to 7 days.
If there is a comparison of Contains or something alike, that might work.
This should return an array of all items that match repeatDays: 'Mon,Tue'
import { ReplaySubject } from 'rxjs/ReplaySubject';
const equalTo$ = new ReplaySubject(1);
const query$ = af.database.list('/data', {query: {
orderByChild: 'repeatDays',
equalTo: equalTo$
}});
equalTo$.next('Mon,Tue');
query$.subscribe(data => console.log(data)); //=> [{repeatDays : 'Mon,Tue' ... }]
Sorry to bother again, but the issue is still not solved. I did try the code above, but it's not working.
The scenario is this: KeyValue pair saved in database is this: { repeatDays: 'Mon, Tue' } And today's day name is: 'Mon'
The result I'm expecting is, I'll be able to get the data node with the key value pair as above. Today's day name is only partial of the data saved in database.
The answer I got above can only get me the data node when the value are exactly same. I need to get the value when it's partially there.