Querying or otherwise working with many nested objects within a doc

Let’s consider this example -

 {
   "type":"university",
   "students":[
        {
         "id":"student_112"
        },
        {
         "id":"student_189"
         },
         {
         "id":"student_1209"
         }
        
    ]
 }

Let’s suppose you are looking to query for documents based on the “id” property of “students” array

  let searchQuery = Query
        .select(SelectResult.expression(Expression.meta().id))
    .from(DataSource.database(db))
    .where(Expression.property("type").equalTo("university")
    .and(Expression.any("STUDENT").in(Expression.property("students"))
    .satisfies(Expression.variable("STUDENT.id").equalTo("student_112"))))
    .limit(limit)

The next part of blog post would be discussing collections and will cover the above example. There are some enhancements to the API . So stay tuned.

2 Likes