Home
Analytics
Dynamic query with mongodb
tadeoj
<div>Hello,</div>
<div> </div>
<div>I have to make a birt report with 3 parameters which should be used in query. The parameters are two dates and a string.</div>
<div> </div>
<div>I tried to do it in beforeOpen dataset as indicated for sql queries, but it has not worked.</div>
<div> </div>
<div>It is possible to make mongo query in Birt with parameters?</div>
<div> </div>
<div> </div>
<div>Thanks.</div>
<div> </div>
Find more posts tagged with
Comments
pricher
<p>Hi,</p>
<p> </p>
<p>As far as I know, it is possible to script the beforeOpen method when using MongoDB. Can you be more explicit when you say "it has not worked"?</p>
<p> </p>
<p>Regards,</p>
<p> </p>
<p>P.</p>
tadeoj
<p class="">Yes,</p>
<p class=""> </p>
<p class="">I write in beforeOpen expression dataset:</p>
<p class=""> </p>
<p class=""><span>this</span><span>.queryText = </span>'{"findQueryExpr": { "ref": "'<span>+params[</span>"ref"<span>].value+</span>'", "sts": { $gt: "'<span>+params[</span>"startDate"<span>].value+</span>'" , $lte: "'<span>+params[</span>"endDate"<span>].value+</span>'"} } , "operationType" : "FIND" , "collectionName" : "events", "queryReadPreference" : "secondary" , "selectedFields" : [ "ref" , "sts" , "rts" , "c.value" , "c.type" , "c.quality" , "r.value" , "r.type" , "r.quality"] }'<span>;</span></p>
<p class=""> </p>
<p class=""><span>And the query is throwing on the total number of documents in the collection regardless of the parameters.</span></p>
<p class=""> </p>
<p class="">Thanks.</p>
pricher
<p>Hi,</p>
<p> </p>
<p>I suggest you check the content of queryText after you create the expression; there might be a small issue when you concatenate the parameter value. One easy way to do this is to start Eclipse in console mode by using the start command eclipsec.exe. Then, in your beforeOpen script, add the following line of code after the this.queryText statement:</p>
<p> </p>
<p><span style="font-family:'courier new', courier, monospace;">Packages.java.lang.System.out.println(this.queryText);</span></p>
<p> </p>
<p>You will then be able to see the exact query content sent to the database in the console window.</p>
<p> </p>
<p>Hope this helps,</p>
<p> </p>
<p>P.</p>