KMongo queries producing different results from Mongo Shell

274 Views Asked by At

I'm currently using KMongo and it's very nice. Simple to use, nice syntax, etc.

But I ran into an issue while querying some data that I cannot figure it out. I'm filtering for some fields and when I run my queries on Mongo Shell or robo 3T it works fine. Nevertheless, when I try to run on my Kotlin application, it (only in some cases) does not work. I'm querying like this:

    collection.find(
            MyEntity::name regex filter.name,
            MyEntity::role eq filter.role,
    )

But I also tried writing a string with the native query receiving the filtering value and I had the same issue. A concrete example is this query:

{ 'role': 'VENDOR', 'name': 'Internal Revenue Service'}

If I run on robo 3T like this:

db.getCollection('MyEntity').find({ 'role': 'VENDOR', 'name': 'Internal Revenue Service'})

I receive the results I expect, but if I run with KMongo, the exactly same query (and I doubled checked with the debugger), I receive nothing in result:

collection.find("{ 'role': 'VENDOR', 'name': 'Internal Revenue Service'}")

When I use regex to query (like in the first example), it seems to return only with small values: if I query for name with 'Internal Revenue Service' it produces no result, but if I query with only 'Internal' the result is correct.

Does anyone have any idea of what it could be? It seems deadly simple, but it's killing me that I can't figure it out.

1

There are 1 best solutions below

0
On BEST ANSWER

I found out one day later that there was an injection of an offset that was wrongfully computed. So, when the query was more specific, it returned nothing. That was kind of sad.