-
Notifications
You must be signed in to change notification settings - Fork 576
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
Realm query objects by array of ids #2781
Comments
Hey @pollend
|
that's nice to know. I saw some sample code floating around that uses the |
You need answer from Realm team. 😅 I based my answer on |
We would like to implement full support for "IN" at some point, but because of the workaround mentioned here with chaining equality with "OR" it hasn't been a high priority. We do have an optimization at a lower level which combines these types of "equal OR equal" chains together, so even though you are writing out the query in long form, the execution should still be quite fast. |
Can we do it on object ids? |
@abhishekmatta999 yes, the workaround works on any type of value. If you are having issues with your query, let us know more details so we can try to help you. |
@ironage Hi, Im getting this error when I'm trying it with object-ids Invalid predicate: '(_id = 606b439ede7a330008506642 OR _id = 606b43a17375130009ef5864 OR _id = 606b43814e9a5900086fc20b OR _id = 606b438a3237c60008596144)': syntax error, unexpected identifier, expecting || or ')' My query is: |
@abhishekmatta999 the best practice is to pass your variables in by argument substitution, then you don't have to worry about the format. With the object id's stored in variables If you really need to hard code the object id's into the query string then they should be formatted into "oid(...)" like this: |
Hi, Any update for 2022 usecases, IN operator is supported NOW!! We need to filter object like this:
Thanks! |
Next release (v10.20.0) will include an enhancement of the |
Hi @kneth, First of All, thanks for this realease, I have a question plz, what about 'NOT IN', how can i achieve this case ? UPDATE I use |
@dridi93 You can use We haven't got around documenting it yet, but you can take a look at one of our tests: https://github.com/realm/realm-js/blob/master/integration-tests/tests/src/tests/queries.ts#L76-L88 |
I am using class MyObject extends Realm.Object {
static schema = {
name: 'MyObject',
properties: {
Id: 'string',
}
}
}
// idList = ['id1', 'id2']
realm.objects(MyObject).filtered('Id IN $0', idList);
// idList = "['id1','id2']"
realm.objects(MyObject).filtered('Id IN $0', idList);
// idList = "{'id1', 'id2'}"
realm.objects(MyObject).filtered('Id IN $0', idList); My current workaround is to just use realm.objects(MyObject).filter(o => idList.includes(o.Id)); |
Hi @tehvgg, the earliest release in the 11 series to include "IN" query support is |
@ironage I thought that might be the case, initially I couldn't upgrade past Thanks! EDIT: |
For me using realm 11.3.1 & realm/react 0.4.3 , I was not able to query the way I was thinking it would work... Its not accepting string array as parameter participantsProfileIds - ['key1', 'key2']
Instead had to use the following workaround:
Not sure which is better, this one above or the |
@geo-vi what is the error that you are getting when passing an array of strings as an argument for the
It is more efficient to use the |
@geo-vi could you open a new bug report in this repository? It would be very helpful to include the exact string array argument and query in a minimal reproduction case if you are able to make one that doesn't include user data. |
Finally i found a way for it to query by multiple object ids in react native.
|
Questions: I want to query by a list of ids but I get this error when I try to query by this:
The expression following 'IN' must be a keypath to a list
Version of Realm and Tooling
The text was updated successfully, but these errors were encountered: