Querying without conditions
You can query documents without applying conditions to queries.
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 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 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 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));
}
}