Andy T
Andy T

Reputation: 9881

How to query for list of properties in a document

I will be receiving flat documents that will have slightly different schemas.

For example:

{
   "FirstName": "Jim",
   "LastName: "Bob"
}

And another one, that would simply have:

{
   "FullName": "Jim Bob"
}

Is it possible to query the Person collection to retrieve the list of unique properties (not the values)?

[
   "FirstName",
   "LastName",
   "FullName"
]

Upvotes: 1

Views: 397

Answers (1)

Jay Gong
Jay Gong

Reputation: 23782

According to my research, it is not supported in cosmos db query syntax so far. You could refer to this similar feedback and adopt the suggestions from cosmos db team.

Also, I think you could get all the names of properties by below coding workaround.

  1. Create and init a hashmap.

  2. Query the documents and get the results array.

  3. Loop the array and convert every json to map.

  4. Push the elements into initial hashmap to make sure the list of properties is unique.

Upvotes: 1

Related Questions