Querying without Conditions

You can query documents without applying conditions to queries.

Returning Whole Documents

Returning Multiple Whole Documents

Call the find() method of a Table object that represents the table. The result is a DocumentStream object, which is a list of Document objects that contain the returned whole OJAI documents.

  public void findDocs(String tablePath) {
    try(Table table = MapRDB.getTable(tablePath)) {
      DocumentStream documentStream = table.find()) {
      for(Document document : documentStream) {
        System.out.println(document);
      }
    }
  }

Returning Single Whole Documents

Call the findById() method of a Table object that represents the table. When calling the method, pass the value of the _id field in the document.

The method returns a Document object that contains the OJAI document.

  public void findDocById(String tablePath, String _id) {
    try(Table table = MapRDB.getTable(tablePath)) {
      System.out.println(table.findById(_id));
    }
  }

Returning Partial Documents by Using Projection

Note: If the field path that you specify for projection does not exist in a document, the query returns the value of the _id field for that document. For example, suppose the field path for a query is a.b.c. A document in the queried table looks like this:
{
  "_id" : "329-98712-RH28937",
  "a" : {
    "b" : "Jelly-filled donut"
  }
}

Also, projecting on the _id field returns only the values of the _id field in the documents queried.

Returning Multiple Partial Documents

Call the find() method of a Table object that represents the table. When calling the method, pass a String object that contains the path or paths of the fields to include in the results. The paths used dotted notation.

The result is a DocumentStream object, which is a list of Document objects that contain the returned partial OJAI documents.

  public void findPartialDocs(String tablePath, String[] fieldPaths) {
    try(Table table = MapRDB.getTable(tablePath)) {
      DocumentStream documentStream = table.find(fieldPaths)) {
      for(Document document : documentStream) {
        System.out.println(document);
      }
    }
  }

Returning Single Partial Documents

Call the findById() method of a Table object that represents the table. When calling the method, pass the value of the _id field in the document, as well as a String object that contains the path or paths of the fields to include in the results. The field paths are in dotted notation.

The method returns a Document object that contains the partial JSON document.

  public void findPartialDocById(String tablePath, String _id, String fieldPath) {
    try(Table table = MapRDB.getTable(tablePath)) {
      System.out.println(table.findById(_id, fieldPath));
    }
  }