# mongodb-plus-boot-starter
**Repository Path**: ASUS_B/mongodb-plus-boot-starter
## Basic Information
- **Project Name**: mongodb-plus-boot-starter
- **Description**: 练习mongodb
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2021-08-30
- **Last Updated**: 2021-09-07
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# mongodb-plus-boot-starter
#### 介绍
练习mongodb
#### 软件架构
软件架构说明
#### 安装教程
1. xxxx
2. xxxx
3. xxxx
#### 使用说明
1. 加载项目模块
com.sun
mongodb-plus-boot-starter
1.0-SNAPSHOT
2.添加连接配置
spring:
data:
mongodb:
host: 127.0.0.1
database: yshopb2c
username: root
password: root
3. 同mybatisplus 一样
实体entity extends BaseMongo
调用方式一:
xxxService extends BaseMongoService
xxxServiceImpl extends BaseMongoServiceImpl implements xxxService
@Autowired
xxxService xxxService;
xxxService.list(); //调用方法
调用方式二:
@Autowired
MongoTemplate mongoTemplate;
BaseMongoUtil xxxMongoUtil = new BaseMongoUtil( (T extends BaseMongo).class,mongoTemplate);
xxxMongoUtil.list(); //调用方法
4. 示例
1)CriteriaWrapper criteriaWrapper = new CriteriaAndWrapper().eq(User::getType, type)
.and(new CriteriaOrWrapper().like(User::getName, word).like(User::getPhone, word));
xxxService.list(criteriaWrapper);
以上查询 类似于 select * from User where Type = type and (Name like '%#{word}%' or Phone like '%#{word}%' );
2)UpdateBuilder up = new UpdateBuilder().inc(YxUser2::getLevel,2);
xxxService.update(up,new CriteriaAndWrapper().eq(YxUser2::getId,id));
以上修改 类似于 update YxUser2 set Level = Level+2 where id = #{id};
更多函数参考 mongodb 文档调用
3)左关联 查询 -
不支持 a left join b on a.id =b.aid left join c on c.bid = b.id ;
仅支持 a left join b on a.id =b.aid left join c on c.aid = a.id ;
CriteriaAndWrapper queryWhere =new CriteriaAndWrapper().in(YxUser2::getUid,new Long[]{157L,171L,182L});
LookUpParam leftTableInfo= LookUpParam.builder().as(YxUser2::getAdressList).form(YxUserAddress2.class).localField(YxUser2::getUid).foreignField(YxUserAddress2::getUid).build()
AggregationWrapper wrapper = new AggregationWrapper();
wrapper.match(queryWhere);
wrapper.lookup(leftTableInfo);
xxxService.aggregate(wrapper.buildAggregation());
or
xxxService.leftJoinList(queryWhere,leftTableInfo);
以上查询类似于 select * from YxUser2 u2 left join YxUserAddress2 ua2 on u2.uid = ua2.uid where u2.uid in (157,171,182);
关联 YxUserAddress2 的查询结果 使用 YxUser2::getAdressList 接收。
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
#### 特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)