In the mongo shell I retrieve ancestors of an element (I built a tree structure with an array of ancestors) using this query:
db.collection.findOne({_id: "some_unique_id"}).ancestors
What is the equivalent code in Java?
My code that doesn’t get the right result is:
BasicDBObject root = new BasicDBObject();
root.put("_id", idObj);
root.put("type", typeObj);
BasicDBObject query = new BasicDBObject("ancestors", root);
DBObject o = locations.findOne(query);
System.out.println(idObj + " - findone => " + o.toString());
Where is the error?
Thanks in advance
The Java equivalent to your mongo shell query is: