Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter question #6

Closed
alperenboyaci opened this issue May 17, 2018 · 4 comments
Closed

filter question #6

alperenboyaci opened this issue May 17, 2018 · 4 comments

Comments

@alperenboyaci
Copy link

alperenboyaci commented May 17, 2018

Hi

can you help me ?
I have a 2 questions


part of my data like that
{
platforms:{"appStore":true, "googlePlay":true, "winStore":false}
}

how can get a result from if appStore is true ?

?$filter=contains(platforms,'appStore') ??? true ?
?$filter=in(platforms,'appStore') ??? true ?


part fo my query like that

?$filter=releaseDate le ' 2018.05.17' and endDate gt '2018.05.17'

date part must be use as a dynamic for now/Date()
how can I solve it like ?$filter=releaseDate le Date() and endDate gt Date()

is there any way for it ?

thanks

@adamspe
Copy link
Owner

adamspe commented May 17, 2018

The first one should just be a simple equality match.

E.g.
?$filter=platforms.appStore eq true

For the later, you'll need to generate and format the date when building the $filter.
E.g.

// not emptying out hour, min, sec
const formatDate = (d) => JSON.stringify(d).replace(/"/g,'');
const now = new Date();
const nowFormatted = formDate(now);
filter = `releaseDate le ${nowFormatted} and endDate gt ${nowFormatted}`;

You can see a few basic date filtering examples in test/filter.js in the date-eq|inc|ge-ordered test cases.

@alperenboyaci
Copy link
Author

alperenboyaci commented May 18, 2018

Hi
Thanks for your help.
I am newbie on odata side with my sql mentality :)
There are many differencies.

I need $expand function for using like inner/outer join for me.
I see $expand is merge data to upper-level but I need data a kind of treeview may be we calll reverse-expand.

Is there any method/way for making it ?
Thanks

picture2

@adamspe
Copy link
Owner

adamspe commented May 21, 2018

First, the library is "odata'ish" in nature (I probably should have named it differently). It leverages many of the odata query arguments and the $filter syntax since they're logical and well defined.

I added $expand rather quickly when someone requested it and I'm not too happy with how it functions (at least WRT to mixing it with $select). In this case, If I'm understanding your question right you just want to expand two levels of references?

Every property referenced in $expand has to point to a reference. In this case I think you should just be able to specify the path you want expanded like publishersId.authorsId which should cause the item pointed to by publishersId and the nested reference authorsId within it. Remember that for $expand to work properly you must specify the ref property in your Mongoose schema for those reference properties, otherwise, Mongoose will simply ignore the request to expand the references quietly.

If you need something fancier than that then you may need to override/extend the behavior in the resource implementation.

@adamspe
Copy link
Owner

adamspe commented Jun 4, 2018

Closing since there hasn't been an update to this thread in a while. If you have further questions let me know. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants