Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-55286

$regex operator inside a Spring Boot @Query annotation unsuccessful

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • ALL
    • Hide

      I would like to retrieve every document with a patchName(String), which contains a given phrase. E.g. "When the user submits a keyword "S2A", he will acquire all matching documents with patch names i.e., "patchName" : "S2A_MSIL2A_20170613T101031_0_64". Since I would like that the phrase is contained into the patch name, I decided to go with $regex, since a text index searches only exact phrases. I managed it to submit the query in the mongodb shell, however, I am not able to reproduce it inside the Spring Boot Repository class at server-side. Hereby I attach some screenshots:

       

      And here is the analogous query, submitted from Spring Boot Repository class:

       

      And this is how I invoke it (p.s. I tried several approaches, but still nothing):

      Whichever approach I take, it still does not work. Even if I submit the exact patch name of the document, it does not retrieve it.

      Hereby I provide you with two example documents (the data originates from the BigEarthNet archive (http://bigearth.net/):

      {
      "_id" : ObjectId("60531c9be17ae9783919549b"),
      "type" : "Feature",
      "location" : [
      [
      20.9996003792675,
      63.3486882292739
      ],
      [
      20.9996003792675,
      63.3379164659186
      ],
      [
      21.0235688072459,
      63.3379164659186
      ],
      [
      21.0235688072459,
      63.3486882292739
      ],
      [
      20.9996003792675,
      63.3486882292739
      ]
      ],
      "properties" :

      { "patchName" : "S2A_MSIL2A_20170613T101031_0_63", "labels" : [ "f" ], "acquisitionDate" : ISODate("2017-01-13T09:10:31Z") }

      ,
      "_class" : "com.tuberlin.dbpro.models.database.MetaJson"
      }

      {
      "_id" : ObjectId("60531c9be17ae9783919549c"),
      "type" : "Feature",
      "location" : [
      [
      20.9996005286705,
      63.3379184119332
      ],
      [
      20.9996005286705,
      63.3271466330944
      ],
      [
      21.0235599998921,
      63.3271466330944
      ],
      [
      21.0235599998921,
      63.3379184119332
      ],
      [
      20.9996005286705,
      63.3379184119332
      ]
      ],
      "properties" :

      { "patchName" : "S2A_MSIL2A_20170613T101031_0_64", "labels" : [ "f" ], "acquisitionDate" : ISODate("2017-01-13T09:10:31Z") }

      ,
      "_class" : "com.tuberlin.dbpro.models.database.MetaJson"
      }

       

       

       

       

       

      Show
      I would like to retrieve every document with a patchName(String), which contains a given phrase. E.g. "When the user submits a keyword "S2A", he will acquire all matching documents with patch names i.e., "patchName" : "S2A_MSIL2A_20170613T101031_0_64". Since I would like that the phrase is contained into the patch name, I decided to go with $regex, since a text index searches only exact phrases. I managed it to submit the query in the mongodb shell, however, I am not able to reproduce it inside the Spring Boot Repository class at server-side. Hereby I attach some screenshots:   And here is the analogous query, submitted from Spring Boot Repository class:   And this is how I invoke it (p.s. I tried several approaches, but still nothing): Whichever approach I take, it still does not work. Even if I submit the exact patch name of the document, it does not retrieve it. Hereby I provide you with two example documents (the data originates from the BigEarthNet archive ( http://bigearth.net/): { "_id" : ObjectId("60531c9be17ae9783919549b"), "type" : "Feature", "location" : [ [ 20.9996003792675, 63.3486882292739 ], [ 20.9996003792675, 63.3379164659186 ], [ 21.0235688072459, 63.3379164659186 ], [ 21.0235688072459, 63.3486882292739 ], [ 20.9996003792675, 63.3486882292739 ] ], "properties" : { "patchName" : "S2A_MSIL2A_20170613T101031_0_63", "labels" : [ "f" ], "acquisitionDate" : ISODate("2017-01-13T09:10:31Z") } , "_class" : "com.tuberlin.dbpro.models.database.MetaJson" } { "_id" : ObjectId("60531c9be17ae9783919549c"), "type" : "Feature", "location" : [ [ 20.9996005286705, 63.3379184119332 ], [ 20.9996005286705, 63.3271466330944 ], [ 21.0235599998921, 63.3271466330944 ], [ 21.0235599998921, 63.3379184119332 ], [ 20.9996005286705, 63.3379184119332 ] ], "properties" : { "patchName" : "S2A_MSIL2A_20170613T101031_0_64", "labels" : [ "f" ], "acquisitionDate" : ISODate("2017-01-13T09:10:31Z") } , "_class" : "com.tuberlin.dbpro.models.database.MetaJson" }          

      Hello,

       

      I have spent hours trying to successfully submit a $regex driven query using the Java Spring Boot @Query annotation. I also tried with the generated query methods based on names, however, still nothing.

      I have already searched in the documentation and throughout the Internet, but I could not identify my mistake. Could anyone back me up on this one?

       

      Regards,

      Pavel Antonov

        1. image-2021-03-18-11-24-43-968.png
          18 kB
          Pavel Antonov
        2. image-2021-03-18-11-38-16-718.png
          25 kB
          Pavel Antonov
        3. image-2021-03-18-11-39-03-720.png
          32 kB
          Pavel Antonov
        4. image-2021-03-18-11-39-20-866.png
          33 kB
          Pavel Antonov
        5. image-2021-03-18-11-39-24-832.png
          33 kB
          Pavel Antonov

            Assignee:
            Unassigned Unassigned
            Reporter:
            paveldushev9@gmail.com Pavel Antonov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: