Reputation: 619
I want to use immutability-helper to update the object contained in my variable, the variable contains the following..
{
"_id": "XXXXX",
"_rev": "XXXXX",
"keys": {
"component": "TEST",
"type": "system"
},
"content": {
"services": {
"event": {
"url": "https://example.net"
},
"copy": {
"url": "https://example.net"
},
"humley": {
"url": "https://example.net",
"credentials": {
"user": "TEST",
"password": "TEST"
}
}
},
"settings": {
"processing": false,
"syncTimeout": {
"interval": 1,
"intervalUnit": "minutes"
},
"products": {
"hum": {
"copySyncDate": "2017-01-21T13:20:12.633Z",
"eventSyncDate": "",
"workspaceSyncDate": ""
}
}
},
"syncTimeout": {
"interval": 1,
"intervalUnit": "minutes"
}
}
}
I am looking to update the values
"hum": {
"copySyncDate": "2017-01-21T13:20:12.633Z",
"eventSyncDate": "",
"workspaceSyncDate": ""
I believe I can use the update function to update and store the new data in a new variable:
const documentUpdate = update(document, XXX);
But I can't work out what XXX needs to be.
Upvotes: 1
Views: 105
Reputation: 2507
You can do something like this:
const documentUpdate = update(
document,
{
content: {
settings: {
products: {
hum: {
$merge: {
copySyncDate: 'value',
}
}
}
}
}
},
)
You could use $set
instead of $merge
if you want to replace the entire block.
Upvotes: 1