v6.3.0 (2025-12-10)
<dependency>
<groupId>net.hasor</groupId>
<artifactId>jdbc-mongo</artifactId>
<version>6.3.0</version>
</dependency>
Impact
- LambdaTemplate interface and JdbcTemplate class
- jdbc-mongo driver
- jdbc-redis driver
Changes
- Added
- New jdbc-mongo driver to operate MongoDB via JDBC protocol.
- jdbc-mongo supported across Mapper annotations, Mapper File, and JdbcTemplate APIs.
- Type-safe MongoDB operations via LambdaTemplate.
- Common MongoDB commands supported, including CRUD, aggregation, and index management.
- Dynamic Command tags in Mapper Files can generate MongoDB commands.
- ResultSetExtractor, RowMapper can consume MongoDB query results.
- Changed
- Prevent misuse of
JedisCmd; it can no longer be created publicly. - Replace existing SQL builders in LambdaTemplate with a unified CommandBuilder.
SqlDialectaddsnewBuilderto create dialect-aware command builders.- Deprecated
setColTemplateandgroupByColTemplatein MapperFile and@Columnas they are not logically applicable.
- Prevent misuse of
- Improved
JedisConnlogs a warning if an error occurs when fetching the version during init.
- Fixed
- Race condition in
AdapterContainerwhen responses arrive before results in multithreaded scenarios causing lock waits onsyncObj. DynamicParsedOOM when a colon:is immediately followed by whitespace in SQL.
- Race condition in
How to use MongoDB?
使用 JdbcTemplate 执行命令
// 1. 获取 MongoDB 连接
Connection mongoConn = ...; // 参考文档:驱动适配器 > JDBC Mongo > 安装与配置
JdbcTemplate jdbc = new JdbcTemplate(mongoConn);
// 2. 插入数据
jdbc.execute("test.user_info.insert({name: 'mali', age: 26})");
// 3. 查询数据
List<Map<String, Object>> list = jdbc.queryForList("test.user_info.find({name: 'mali'})");
// 4. 更新数据
jdbc.execute("test.user_info.update({name: 'mali'}, {$set: {age: 27}})");
// 5. 删除数据
jdbc.execute("test.user_info.remove({name: 'mali'})");
使用 Mapper 接口操作
// 1. 定义实体类
@Table("test.user_info")
public class UserInfo {
@Column("uid")
private String uid;
@Column("name")
private String name;
// getters and setters
}
// 2. 定义 Mapper 接口
@SimpleMapper
public interface UserInfoMapper extends BaseMapper<UserInfo> {
@Insert("test.user_info.insert(#{user})")
int saveUser(@Param("user") UserInfo user);
@Query("test.user_info.find({uid: #{uid}})")
UserInfo loadUser(@Param("uid") String uid);
}
// 3. 使用 Mapper
try (Session session = config.newSession(mongoConn)) {
UserInfoMapper mapper = session.createMapper(UserInfoMapper.class);
// 保存
UserInfo user = new UserInfo();
user.setUid("1111");
user.setName("mali");
mapper.saveUser(user);
// 查询
UserInfo loaded = mapper.loadUser("1111");
}
使用 LambdaTemplate 操作
// 1. 获取 MongoDB 连接
Connection mongoConn = ...;
LambdaTemplate lambda = new LambdaTemplate(mongoConn);
// 2. 插入数据
UserInfo user = new UserInfo();
user.setUid("1111");
user.setName("mali");
lambda.insert(UserInfo.class).applyEntity(user).executeSumResult();
// 3. 查询数据
UserInfo loaded = lambda.query(UserInfo.class)
.eq(UserInfo::getUid, "1111")
.queryForObject();
// 4. 更新数据
lambda.update(UserInfo.class)
.eq(UserInfo::getUid, "1111")
.updateTo(UserInfo::getName, "dative")
.doUpdate();
// 5. 删除数据
lambda.delete(UserInfo.class)
.eq(UserInfo::getUid, "1111")
.doDelete();