Elasticsearch: remove/update field inside nested object
By : shan
Date : March 29 2020, 07:55 AM
I wish this helpful for you , To add a new element to your nested field you can proceed like this: code :
$ curl -XPOST 'localhost:9200/index/type/1212/_update?pretty' -d '
{
"script" : "ctx._source.list_data += newElement",
"params": {
"newElement": {
"list_id" : 121,
"timestamp" : 1469050965
}
}
}'
$ curl -XPOST 'localhost:9200/index/type/1212/_update?pretty' -d '
{
"script" : "ctx._source.list_data.removeAll{it.list_id == remove_id}",
"params": {
"remove_id" : 122
}
}'
|
N1QL nested json, query on field inside object inside array
By : Jannatul Naeem
Date : March 29 2020, 07:55 AM
I hope this helps . I have json documents in my Couchbase cluster that looks like this , Here is a query without the providerType. code :
EXPLAIN SELECT *
FROM giata_properties AS gp
WHERE ANY v WITHIN gp.giata_properties.propertyCodes.provider[*].code SATISFIES v.`value` = '071801' END;
CREATE INDEX idx1 ON giata_properties( DISTINCT ARRAY v.`value` FOR v WITHIN SELF.giata_properties.propertyCodes.provider[*].code END );
|
Update field inside a nested JSON object based on key using jq
By : user2940604
Date : March 29 2020, 07:55 AM
it fixes the issue You can just create a mapping of the ids you want to update and the value to update to. Then use that mapping to update the corresponding values. code :
$ jq --argjson m '{"id1":"false","id2":"true","id3":"false","id4":"false"}' '
.values |= with_entries(.value.enabled = $m[.key])
' input.json
|
MongoDB - Update field in an array object based on nested array's field value
By : user3611529
Date : March 29 2020, 07:55 AM
I hope this helps . I am trying to update a field inside array of objects, where field in nested array is equal to a value. , Please try this : code :
db.Product.findOneAndUpdate(
{ _id: 123 },
{
$set: {
'variations.$[item].valueList.$[nameField].value': 'newRed',
'variations.$[item].picture': 'newURL' // item is each object in variations which is being checked in arrayFilters.
}
},
{
arrayFilters: [{ 'item.valueList.value': 'oldRed' }, { 'nameField.value': 'oldRed' }],
new: true
}
)
{
"_id" : 123,
"variations" : [
{
"id" : 1,
"picture" : "https://example.picture.com",
"valueList" : [
{
"name" : "color",
"value" : "oldRed"
},
{
"name" : "size",
"value" : "M"
},
{
"name" : "color",
"value" : "oldRed"
}
]
},
{
"id" : 2,
"picture" : "https://example.picture.com",
"valueList" : [
{
"name" : "color",
"value" : "black"
},
{
"name" : "size",
"value" : "M"
}
]
},
{
"id" : 3,
"picture" : "https://example3.picture.com",
"valueList" : [
{
"name" : "color",
"value" : "oldRed"
},
{
"name" : "size",
"value" : "M"
}
]
}
]
}
/* 1 */
{
"_id" : 123,
"variations" : [
{
"id" : 1,
"picture" : "newURL",
"valueList" : [
{
"name" : "color",
"value" : "newRed"
},
{
"name" : "size",
"value" : "M"
},
{
"name" : "color",
"value" : "newRed"
}
]
},
{
"id" : 2,
"picture" : "https://example.picture.com",
"valueList" : [
{
"name" : "color",
"value" : "black"
},
{
"name" : "size",
"value" : "M"
}
]
},
{
"id" : 3,
"picture" : "newURL",
"valueList" : [
{
"name" : "color",
"value" : "newRed"
},
{
"name" : "size",
"value" : "M"
}
]
}
]
}
|
Update object inside nested array in Mongodb
By : jasminder88
Date : March 29 2020, 07:55 AM
Hope this helps I have a document that looks like this. Where I need to update a specific object inside a nested array. I need to edit the text object with the name which is having a locale of en. , url field is an array, so you need to use this syntax: code :
db.getCollection('general').update({
"source": "homepage"
}, {
"$set": {
"url.$[urlId].text.$[textId].name": "YOYO"
}
}, {
"arrayFilters": [
{ "urlId.type": "admindsg" },
{ "textId.locale": "en" },
],
"multi": true
})
|