[Vuejs]-Fetching data from mongodb and electron js using ipc renderer

0👍

Best way ignore this type of format is, after getting result from DB encode in json and then of font-end decode json format which will generate desire result. Like this-

render.js

ipcMain.on('get-result', (event) => {
    todolist.aggregate([
        {
            $sort:{
                _id:-1
            }
        }
    ])
    .exec((err, result) => {
        if (!err && result.length) {
            event.sender.send('got-it', {
                status: true,
                result: JSON.stringify(result)
            });
        } else {
            event.sender.send('got-it', {
                status: false
            });
        }
    });
});

component.vue

this.$electron.ipcRenderer.send('get-result')
      this.$electron.ipcRenderer.on('got-it', (event, data) => {
        if (data.status) {
          this.allResult = JSON.parse(data.result)
        }
        else{
          this.allResult = ''
        }
      })

Leave a comment