Typically, my process would include the following steps:
var res = {};
res = { _id: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5327362027132736202736217d303c3e">[email protected]</a>',
password: 'ABCDEF',
phone: '123123123',
name: 'Torben Tester',
userLog: [
{ date: 1510561026, text: 'was CREATED' },
{ date: 1510593431, text: 'was UPDATED' }
]
}
res.foo = "bar";
delete res.password
delete res.userLog
After these operations, the resulting object would be as follows:
{ _id: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aedacbdddaeedacbdddacbdc80cdc1c3">[email protected]</a>',
phone: '123123123',
name: 'Torben Tester',
foo: 'bar'
}
However, when retrieving the record from MongoDB
usersTable.findOne (
{ _id: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="592d3c2a2d192d3c2a2d3c2b773a3634">[email protected]</a>' }
,function (err, data) {
res = data
}
The variable res
remains unchanged after this operation
Any attempts to modify it afterwards, such as:
res.foo = "bar";
delete res.password
delete res.userLog
Lead to no visible changes. There are no errors and res
retains its original form.
I am puzzled by this behavior. Could it be that res
has a different nature when retrieved from mongodb? (It is not an array, as I have verified)
Even upon logging res
, its structure appears identical in both scenarios.
If you have any insights or suggestions, they would be greatly appreciated. I have been stuck on this issue for quite some time.
To provide further clarity, here is the actual code snippet:
usersTable.findOne (
{ _id: userID }
,function (err, data) {
show("============BEFORE================")
show({data})
data.agentName = agentName + "XXXX";
delete data.password
delete data.userLog
show("============AFTER================")
show({data})
return resolve(data);
}