Search code examples
mongodbjasper-reportsuuid

Jaspersoft : use UUID in mongoDB query (filter by id)


I try to make a findQuery for mongoDB in jaspersoft studio but when I try to use a UUID in the process, I always have 0 results.

Example query :

{
  'collectionName' : 'Orders',
  'findQuery' : {
    "_id" :  UUID("4925b1a6-5cd6-6d19-9f2a-7a0083a7bb9a")
  }
}

Is there something wrong in my query in your opinion ?

Thanks for your help


Solution

  • I found how to use a UUID in a mongo query.

    You should first convert your UUID in base64, to do so I used 2 online converters, the first one gave me the 12 first base64 caracters, the second one the 12 last 

    (yes, this is strange).

    To give you a concrete example

    Basic UUID : 41e73145-2489-54e1-d2fc-d400bea5e9b1

    Site 1 https://www.fileformat.info/tool/guid-base64.htm : QecxRSSJVOHS/AAA1AC+pQ

    Site 2 https://toolslick.com/conversion/data/guid : RTHnQYkk4VTS/NQAvqXpsQ==

    Final base64 result :  QecxRSSJVOHS/NQAvqXpsQ==

    Then to use it in Jasper, you'll need this syntax : 

    _id: new BinData(4,"QecxRSSJVOHS/NQAvqXpsQ==")