aql - Arangodb removing subitems from document -


how 1 remove subitems document. have document called sales each sale has sale.item contains {name,price,code}.

i want remove each item not valid, checking code blank or null.

trying below fails errors, not sure if need use sub-query , how.

for sale in sales item in sale.items     filter item.code == "" remove item in sale.items 

another attempt

for sale in sales     let invalid = (         item in sale.items             filter item.code == ""         return item     )  remove invalid in sale.items let removed = old return removed 

the following query rebuild items each document in sales. keep item code not null , not empty string:

for doc in sales    let newitems = (     item in doc.items        filter item.code != null && item.code != ''        return item     )    update doc { items: newitems } in sales 

here test data used:

db.sales.insert({    items: [      { code: null, what: "delete-me" },      { code: "", what: "delete-me-too" },      { code: "123", what: "better-keep-me" },      { code: true, what: "keep-me-too" }   ] }); db.sales.insert({    items: [      { code: "", what: "i-will-vanish" },     { code: null, what: "i-will-go-away" },     { code: "abc", what: "not me!" }   ] }); db.sales.insert({    items: [      { code: "444", what: "i-will-remain" },     { code: null, what: "i-will-not" }   ] }); 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -