dear all,
i’m wondering using n1ql how can i remove from an object all key value attributes that do not satisfy a given condition.
for instance, let us consider this doc
{
“tutorial”: {
“age”: 46,
“children”: [
{
“age”: 17,
“fname”: “Aiden”,
“gender”: “m”
},
{
“age”: 2,
“fname”: “Bill”,
“gender”: “f”
}
],
“email”: "dave@gmail.com",
“fname”: “Dave”,
“hobbies”: [
“golf”,
“surfing”
],
“lname”: “Smith”,
“relation”: “friend”,
“title”: “Mr.”,
“type”: “contact”
}
}
let us suppose that i want to prune out from tutorial all fields whose value is set to “Dave”
I’ve seen that N1ql provides function for array manipulation thus the following query allows me to generate an array of attributes-values that satisfy the condition.
SELECT
array f FOR f in OBJECT_pairs(tutorial) when f.value
<>“Dave” END as f1
FROM tutorial
however, i would need to define from this array an object composed of all the listed attribute-values
is it possible to achieve this with n1ql?
thanks