MongoDB store related queries



  • I have a few queries for the MongoDB store:

    1. Can we have additional collections in the MongoDB store along with the jsreport's existing collections?
    2. We want to store some domain-related mappings with the template's shortid in these. So during any operations is there any chance of losing these additional collections?
    3. Instead of passing the template identifier like shortid and data, we will be passing some domain-related information in the API request, and based on the information, we will pick the jsreport template's shortid by querying the custom-made collection. Is this possible? Can we achieve this using a middleware?


  • Can we have additional collections in the MongoDB store along with the jsreport's existing collections?

    Yes

    We want to store some domain-related mappings with the template's shortid in these. So during any operations is there any chance of losing these additional collections?

    No.

    Instead of passing the template identifier like shortid and data, we will be passing some domain-related information in the API request, and based on the information, we will pick the jsreport template's shortid by querying the custom-made collection. Is this possible? Can we achieve this using a middleware?

    Maybe you can implement jsreport script that will handle choosing the right template.
    https://playground.jsreport.net/w/anon/zK5Y8PFp



  • Do you mean, every request will go to this jsreport template and then it will forward?

    Is there any way we can do this using middleware in the server.js?



  • Do you mean, every request will go to this jsreport template and then it will forward?

    Yes

    Is there any way we can do this using middleware in the server.js?

    You can try experimenting with something like this

    jsreport.on('express-before-odata', (app) => {
        app.use('/api/report', (req, res, next) => {
          req.body = JSON.parse(req.body)
          req.body.template = { name: 't1' }
          next()
        })
      })
    


  • Hi,

    This is working for us. But when we build some templates in jsreport and click on Run for preview, it still hits the custom middleware that we created.

    Is there any way to distinguish between the other API requests and the jsreport's preview requests?



  • The requests from the studio have in the payload options.preview=true


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.