Sahar Ben-Shushan
Sahar Ben-Shushan

Reputation: 297

Extra unwanted backslash in Morphia Query object

I'm using Morphia 1.5.2 (Java 8) as a driver for MongoDB (V4.x), trying to use Search for a phrase, so my code looks like :

datastore.find(myEntity).disableValidation().search("\\\"" + textToFilter + "\\\"");

Debug looks good, but in running time the query is being sent with the three backslashes instead of just one, and the query return 0 results.

What am I missing? thanks!

actual generated query: "$text" : { "$search" : "\\\"filteredText\\\"" }

Upvotes: 0

Views: 63

Answers (2)

whaley
whaley

Reputation: 16265

try this:

datastore.find(myEntity).disableValidation().search("\"" + textToFilter + "\"");

Copied and pasted from the official github issue tracker at https://github.com/MorphiaOrg/morphia/issues/1453 . I would have proposed this as an edit to a previous answer, as a reasonable person would have, but the moderators decided to delete the answer instead. Hope you weren't too delayed in getting your answer.

Upvotes: 1

Sahar Ben-Shushan
Sahar Ben-Shushan

Reputation: 297

datastore.find(myEntity).disableValidation().search("\"" + textToFilter + "\"");

Thanks @evanchooly !

Upvotes: 0

Related Questions