简体   繁体   中英

How to find common struct for all documents in collection?

I have an array of documents, that have more or less same structure. But I need find fields that present in all documents. Somethink like:

{
  "name": "Jow",
  "salary": 7000,
  "age": 25,
  "city": "Mumbai"
},
{
  "name": "Mike",
  "backname": "Brown",
  "sex": "male",
  "city": "Minks",
  "age": 30
},
{
  "name": "Piter",
  "hobby": "footbol",
  "age": 25,
  "location": "USA"
},
{
  "name": "Maria",
  "age": 22,
  "city": "Paris"
},

All docs have name and age . How to find them with ArangoDB?

You could do the following:

  • Retrieve the attribute names of each document
  • Get the intersection of those attributes

ie

LET attrs = (FOR item IN test RETURN ATTRIBUTES(item, true))
RETURN APPLY("INTERSECTION", attrs)

APPLY is necessary so each list of attributes in attrs can be passed as a separate parameter to INTERSECTION .

Documentation:

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