Forgive me but I have been trying to solve the problem for several days, but I can not locate the problem.
I am downloading from mongoDB^14..(with mongoose) two arrays with complementary data. One contains the user data, the other the user survey records. Both arrays are related through the user's email:
/***************************************************************
This is what I download from mongoDB with Nodejs
****************************************************************
const user = require ('../models/user');
const test = require ('../models/test');
let users = await user.find ({email:userEmail});
let tests = await test.find ({email:testEmail});
Request:
let users: [
{name:'pp', email:'pp@gmail.com},
{name:'aa', email:'aa@gmail.com'}
];
let tests: [
{email:'pp@gmail.com', satisfaction:'5'},
{email:'aa@gmail.com', satisfaction:'2'}];
*****************************************************************************/
Now I try to relate both json arrays using:
for (let i = 0; i < prof1.length; i++) {
for (let z = 0; z < registro1.length; z++) {
if (users[i].email==tests[z].email){
users[i]['satisfation'] = test[z].satisfation;
}
}
}
If I do a console.log(users[0]) my wish is:
{name:'pp', email:'pp@gmail.com', satisfation:'5'}
But I receive:
{name:'pp', email:'pp@gmail.com'}
But attention¡¡¡¡ If I do a console.log(users[0].satisfation)
The result is: 5
?????? Please can someone help me. Thank you very much
Note: If I instead of downloading the mongodb arrays, I write them by hand. So it works perfectly. Can it be a lock on the models?
WIDE INFORMATION Although I have given a simple example, the user and test arrays are much more complex in my application, however they are modeled and correctly managed in mongoDB. The reason for having two documents in mongoDB is because there are more than 20 variables in each of them. In user, I save fixed user data and in the test the data that I collect over time. Later, I lower both arrays to my server where I perform statistical calculations and for this I need to generate a single array with data from both arrays. I just take the test data and add it to the user to relate all the parameters. I thought that in this way it would unburden the mongoDB to carry out continuous queries and subsequent registrations, since I perform the operations on the server, to finally update the arry test in mongoDB. When I query the database I receive the following array of documents:
let registroG = await datosProf.find({idAdmin:userAdmin });
res.json(registroG);
This is the response received in the front client:
If I open the object the document [0] would be:
**THE QUESTION **: Why when I try to include a value key in the object it doesn't include it?