Result Reading
With the default preRead=true, find / findOne expand document fields for entity mapping. Without a projection, _ID and _JSON document columns are also available.
Read Projected Fields
A projection returns only the projected fields, without synthetic _ID or _JSON columns. Inclusion projections preserve the declared column order. MongoDB includes _id by default, so exclude it explicitly when reading a single business field:
String name = jdbc.queryForString(
"test.user_info.find({uid: ?}, {_id: 0, name: 1})",
new Object[] { "1001" });
Read a Field by Name
Without a projection, read business fields by column name:
List<String> names = jdbc.queryForList(
"test.user_info.find({uid: ?})",
new Object[] { "1001" },
(rs, rowNum) -> rs.getString("name"));
With preRead=false, read the original document instead of expecting expanded columns:
List<String> documents = jdbc.queryForList(
"test.user_info.find({}).limit(10)",
(rs, rowNum) -> rs.getString("_JSON"));
Without an output projection, read aggregate documents from _JSON. To map group results or computed fields to properties, add $project at the end of the pipeline; the default preRead=true exposes those fields as result columns. _ID exposes ObjectId values only; read numeric or string _id from the document field.
Limit the Returned Data
Specify limit on find or $limit in aggregate. Disabling preRead does not make ResultSet.next() fetch one server page at a time.
For JSON-to-object mapping, see JSON Field Mapping.