简体   繁体   中英

Exclude a certian field or make it Null inside a AQL query

I have problem. I have a collection orders . I want to get all documents and all field except the field dataOriginSystem inside metaData . Is there an option to exclude this value, or make it null?

SELECT * EXCEPT(ColumnNameX, [ColumnNameY, ...])
FROM TableA

This my collection orders :

[
{'_id': 'orders/213123',
 'contactEditor': {'name': 'Max Power',
  'phone': '1234567',
  'email': 'max@power.com'},
 'contactSoldToParty': {'name': 'Max Not',
  'phone': '123456789',
  'email': 'maxnot@power.com'},
 'isCompleteDelivery': False,
 'metaData': {'dataOriginSystem': 'Goods',
  'dataOriginWasCreatedTime': '10:12:12',},
 'orderDate': '2021-02-22',
 'orderDateBuyer': '2021-02-22',
},
{'_id': 'orders/12323',
 'contactEditor': {'name': 'Max Power2',
  'phone': '1234567',
  'email': 'max@power.com'},
 'contactSoldToParty': {'name': 'Max Not',
  'phone': '123456789',
  'email': 'maxnot@power.com'},
 'isCompleteDelivery': False,
 'metaData': {'dataOriginSystem': 'Goods',
  'dataOriginWasCreatedTime': '10:12:12',},
 'orderDate': '2021-02-22',
 'orderDateBuyer': '2021-02-22',
 },
]

AQL

FOR doc IN orders RETURN doc

I want something like

FOR doc IN orders RETURN doc WITHOUT metaData_dataOriginSystem
FOR doc IN orders RETURN doc AND metaData_dataOriginSystem = NULL

So that the returned documents do not have the field metaData_dataOriginSystem or the field should be Null

What I want (the other fields should all exist!)

[
{'_id': 'orders/213123',
 ...
 'isCompleteDelivery': False,
 'metaData': {<Removed>,
  'dataOriginWasCreatedTime': '10:12:12',},
 ...
},
OR
{'_id': 'orders/12323',
 ...
 'isCompleteDelivery': False,
 'metaData': {'dataOriginSystem': Null,
  'dataOriginWasCreatedTime': '10:12:12',},
 ...
 },
]

Use UNSET() or UNSET_RECURSIVE() .

UNSET(document, attributeName1, attributeName2, ... attributeNameN) → doc

Remove the attributes attributeName1 to attributeNameN from document. All other attributes will be preserved.

FOR doc IN orders RETURN UNSET( doc, "orderData", "dataOriginSystem")

If you want to remove a nested value, you need to Merge

FOR doc IN orders RETURN MERGE(doc, {metaData: UNSET(doc.metaData, "dataOriginSystem")})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM