DocumentDB SQL Iteration - DocumentDB SQL

What is Iteration in DocumentDB SQL?

The Microsoft added a new construct that can be used with IN keyword to provide support for iterating over JSON arrays in DocumentDB SQL. The support for iteration is provided in the FROM clause.

Consider the three documents from the previous examples again.

The below code is the AndersenFamily document.

The below code is the SmithFamily document.

The below code is the WakefieldFamily document.

Consider a simple example without IN keyword in FROM clause.

Iteration

The query which will return all the parents from the Families collection is given below:

On executing the above query the following result is produced:

From the above result you can see that, the parents of each family are displayed in a separate JSON array.

Consider another example in which we use the IN keyword in FROM clause.

iterations

The query which contains the IN keyword is given below:

On executing the above query the following result is produced:

From the above example you can see that with iteration, the query that performs iteration over parents in the collection has different output array. There for all the parents from each family are added into a single array.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

DocumentDB SQL Topics