How to Query MongoDB Data through the Parameter in BIRT

Problem description & analysis

There is a collection sample in MongoDB database, as shown below:

{

        "_id" : ObjectId("60d2d5c7dcb4a41f6bdc8936"),

        "id" : 1,

        "account" : "abc",

        "vendor" : "amazon"

}

{

        "_id" : ObjectId("60d2d5c7dcb4a41f6bdc8937"),

        "id" : 2,

        "account" : "abc",

        "vendor" : "overstock"

}

{

        "_id" : ObjectId("60d2d5c7dcb4a41f6bdc8938"),

        "id" : 3,

        "account" : "adf",

        "vendor" : "amazon"

}

We are trying to query the document where the id is 2 using the parameter. Below is the desired result:

_id

id

account

vendor

60d2d5c7dcb4a41f6bdc8937

2

abc

overstock

Solution

Write the following script p1.dfx in esProc:

A

1

=mongo_open("mongodb://127.0.0.1:27017/raqsoft")

2

=mongo_shell@x(A1,"sample.find({\"id\":"/id/"})").fetch()

Explanation:

Set the script parameter id, whose value is 2.

A1  Connect to database raqsoft on mongodb server through IP: 127.0.0.1 and port 27017 without the username and password.

A2   Query the database and return result. @x option enables auto-closing he database connection after the code is executed.

See How to Call an SPL SCript in Java to learn about the method of integrating the SPL script with a Java program.

Q & A Collection

https://www.eclipse.org/forums/index.php/t/1075897/