The architecture of the JSON object looks different when I pass it to the client side

Here is my diagram

var mongoose     = require('mongoose');
var Schema       = mongoose.Schema;

var messageSchema   = new Schema({
    requestNumber: String,
    requestedDateTime: String,
    reasons: String,
    state: String,
    hospital: String,
    phone: String,
    status: {type: String, default: 'Pending'},
    latestUpdate: Date,
    createdAt: {type: Date, default: Date.now}
});

module.exports = mongoose.model('Requests', messageSchema);

Below I return a collection with three components in it

ipcMain.on('load-requests', function(event) {

  hosSchemaModel.find(function(err, hosSchema) {
        if (err) {
          console.log('inside error') // return res.send(err);
        } else {

          event.sender.send('requests-results', hosSchema) // this line of code passes hosSchema to the client side

          console.log(hosSchema[0].state) //prints the state attribute of the first component in the collection without any errors.

        }
    });
});

When I try console.log(hosSchema)on the server, I get the following listing to the terminal: terminal result

and I could successfully access properties such as the status of the first component in the collection by accessing its index hosSchema[0].status.

Below I am trying to print hosSchemato the console (in the interface)

ipcRenderer.on('requests-results', (event, hosSchema) => {
    console.log(hosSchema)
  })

I get a result different from what they were looking for in the terminal. below - image client side result

and hosSchema[0].statusreturns undefined.

My questions:

1) why hosSchema[0].statusdoes not work in the interface?

2) What is the correct way to access properties on the client side?

+4
1

, , hosSchema[0]._doc.status hosSchema[0].status

+2

Source: https://habr.com/ru/post/1683392/


All Articles