loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Filter on level 2 properties

Open daankets opened this issue 12 years ago • 244 comments

I am trying to use the ?filter rest method, in order to query on nested properties. However, this doesn't seem to work:

/someResource?filter[where][field.subField][like]=abc

neither does this (which I think is wrong anyway):

/someResource?filter[where][field][subField][like]=abc

Any hints?

daankets avatar Aug 29 '14 12:08 daankets

Which connector are you using?

fabien avatar Aug 29 '14 13:08 fabien

Memory in dev, mongo in test and beyond. It's the memory connector that has the issues. We use this one for our dev setup as it resets upon restart...

It's the 'dot' notation that is working with mongo.

daankets avatar Aug 29 '14 13:08 daankets

This is currently a limitation of the memory connector.

@raymondfeng perhaps we can use something like https://github.com/logicalparadox/filtr or https://github.com/crcn/sift.js to enable this

fabien avatar Aug 29 '14 13:08 fabien

Well, the nice thing about the memory connector is that it resets, so you test every run with a clean sheet. And of course it's rather speedy ;-)

daankets avatar Aug 29 '14 13:08 daankets

Of course - however, you can easily reset the test database before you start, like this:

app.datasources['db'].automigrate(next);

fabien avatar Aug 29 '14 13:08 fabien

Will this drop the entire schema?

daankets avatar Aug 29 '14 13:08 daankets

Yes, but in the case of MongoDB collections will be empties and indexes re-created. There's no real schema, like with SQL databases.

fabien avatar Aug 29 '14 13:08 fabien

Sure. Just calling it a 'schema' as a 'habit'

daankets avatar Aug 29 '14 13:08 daankets

Of course! While collections are being recreated, they are not really removed from the database first. So any obsolete collections will stay around, until you delete them, or the database itself. AFAIK loopback will create the db for you, in case it doesn't exist.

fabien avatar Aug 29 '14 13:08 fabien

@fabien These libraries are interesting:

  • https://github.com/logicalparadox/filtr
  • https://github.com/crcn/sift.js

I also looked at:

  • https://github.com/louischatriot/nedb

Keep in mind, RDBs won't support nested queries.

raymondfeng avatar Aug 29 '14 16:08 raymondfeng

@raymondfeng sift.js looks good to me, but it doesn't support skip/limit. nedb does, but it seems quite a bit more involved. It can probably be implemented as a new connector altogether.

Users should be made aware of the limits of RDBM's, which is perhaps easiest when having this as a separate connector - so users have to be explicit about it, instead of relying on the memory connector (for tests and so forth) to support any type (both SQL as well as NoSQL style) of query. It's probably easy to copy the mongodb connector's query normalization code and implement this.

Here are some more libraries of interest:

  • https://github.com/kawanet/obop
  • http://kawanet.github.io/kagodb/
  • https://github.com/sergeyksv/tingodb (but why use this, over mongodb?)
  • ~~https://github.com/bevry/query-engine~~ (nevermind, too heavy)

fabien avatar Aug 30 '14 10:08 fabien

How this can work for mysql connector? I have same issue

yagobski avatar Nov 24 '14 21:11 yagobski

Looks like Loopback currently does not support nested include filtering. This seems like a huge limitation. I don't believe the db connector should make any difference because ideally the Loopback framework would work the same regardless of what db connector you're using

stringbeans avatar Dec 19 '14 19:12 stringbeans

i'm having the same problem trying to do a nested include. Any solution ?

weslley39 avatar Jan 20 '15 16:01 weslley39

So are there any plans to support nested properties? Is there any way to get the "native" mongodb-connection so we can query the database without the loopback abstraction?

GameScripting avatar Jan 22 '15 22:01 GameScripting

Hey! I've got the Same Problem. I want to query a List of objects based on the property of an related model as well as the property of the wanted model e.g:

Event.find( { where: { and: [ { endDate : { lt : givenDate}}, { location.name : "Abc" }]} }, cb );

So, am I right, that this is not supported atm?

dominikriedel avatar Jan 27 '15 22:01 dominikriedel

I want to query a List of objects based on the property of an related model as well as the property of the wanted model. So, am I right, that this is not supported atm?

You are right, this it not supported yet.

bajtos avatar Jan 28 '15 08:01 bajtos

so the easiest way would be to just query via SQL? Without any further knowlage: is there any caching mechanism I could use?

dominikriedel avatar Jan 28 '15 08:01 dominikriedel

Can we upvote on this feature?

pungoyal avatar Feb 27 '15 13:02 pungoyal