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 By mongo string id like (~) #94
Comments
Digging more in the issue, i have found a way to do it: (tested and it's working)
the above code filter id in a range of ids that starts with '612a'. ( id ~ '612a') or ( id > '612a') could you please add a feature that converts: ( id ~ '612a') to the above example? much appreciated! Thanks! :) |
Hi @chlegou 👋 It should work with |
hi again, I have made new tests, but didn't worked. i tried many things getting different results: (Before, remember that my id is of type String in entity).
none on the working queries gave correct answer. here is objectId list i have: I'm working with version V1.0.5 waiting for your answer. |
I'm sorry it should have been |
again, not working, here is the tests i made:
I don't know if this info is important or not, here is how i'm passing the document to spring data repository:
could you please provide me with working query for you as screenshot? |
You were right, the problem has to do with the ObjectId. My queries were not working as expected. I did some research and was able to get the thing done with the $where operator:
It returns all the documents which have the string The problem is that this executes the JS code for each document from what I've read, it may not be always performant. There is also another issue regarding the implementation of this feature: the field's real name is A possible solution would be to let the user use the
Not sure but it may lead to security issues. Another possible solution would be to transparently use the What do you think? |
I have tested to code you gave me, but didn't worked. it's returning 500 Internal Server Error. I think it's not available in Mongo yet.
yeah who knows, as it may give full access to the collection.
$ObjectId is an Hex String of length 24: https://stackoverflow.com/a/25418489/4771750 knowing this, if the field has @id and with type String (Must check validity for Id with type BigInteger or Long! I think it's not an Objectid in that case) , we fill the input search string with paddings '00..00' and 'ff..ff' till having 24 length hex string. Then, following the search query, we build the document:
like this, we get the perfect solution like we want it without fearing of any security measures. |
I went on with one of the solutions I proposed earlier, using You should finally be able to do the following with the new version https://github.com/turkraft/spring-filter/releases/tag/1.0.7:
Which will produce:
Closing the issue for now. Feel free to reopen if it still does not work. :) |
It's working! 👍 thanks! |
Hi there,
when i was testing you library, nice work btw, I was trying to filter entity ID by like '~' but wasn't working.
logging the document value, this is how it's written (when using like '~' ):
btw, here is my entity:
I have made some search, and i find out that i can't search by id portion, since it's saved as ObjectId, and not as string.
link: https://stackoverflow.com/a/32777342/4771750
... but do you know a way to do it?
The text was updated successfully, but these errors were encountered: