San San - 3 months ago 19
Java Question

Tree structured modelled in mongodb with materialized paths: how to write query in java to get all child nodes using parent path

I have been reading a tutorial on Modelling Tree Structures with Materialized Paths:

This tutorial includes a query for finding children by using the parent's path. But my problem is how to do the query in java.

I tried to implement this using the code below:

BasicDBObject query = new BasicDBObject();
query .put("Path", java.util.regex.Pattern.compile("/,Programing,/"));
DBCursor doc = example.find(query );

while(doc.hasNext())
{
System.out.println(doc.next());
}

San San
Answer
          Pattern path = Pattern.compile("Programing");
          BasicDBObject query = new BasicDBObject();
          query.put("Path", path);

          DBCursor doc = example.find(query ); 

          while(doc.hasNext())
          {                    
            System.out.println(doc.next());
          }
Comments