14.MongoDBUtils工具类
2024-08-31 13:18:43
1.
public class DbUtils { public static MongoCollection<Document> getMongoCollection(String localhost, int port) {
MongoClient mongoClient = new MongoClient(localhost, port);
MongoDatabase mongoDatabase = mongoClient.getDatabase("admin");
System.out.println("Connect to database successfully");
MongoCollection collection = mongoDatabase.getCollection("person");
return collection;
}
}
2.
public class ListEnterpriseAdapterDaoImpl implements ListEnterpriseAdapterDao{ @Override
public void saveEnterprise(List<Enterprise> enterpriseList,long projectId) { MongoCollection<Document> collection = DbUtils.getMongoCollection("127.0.0.1",27017);
log.info("数据开始保存的mongoDB...............");
for(Enterprise enterprise:enterpriseList){
String jsonData = JSON.toJSONString(enterpriseList);
Random random = new Random();
long fid = random.nextLong();
long fTenantId = random.nextLong();
Document document = new Document();
document.append("F_ID", fid);
document.append("F_PROJECT_ID", projectId);
document.append("F_RAW_DATA", jsonData);
collection.insertOne(document);
}
log.info("数据开始保存的mongoDB结束...............");
}
}
最新文章
- git提交项目到已存在的远程分支
- python的内存管理机制
- 【opencv学习笔记】SetImageROI函数设置ROI区域的作用及用法
- C++ Primer:第七章:类
- 【和我一起学python吧】Python安装、配置图文详解
- Python自动化运维之27、Django(一)
- ●BOZJ 3144 [Hnoi2013]切糕
- linux子系统折腾记 (二)
- Linux编译静态库与共享库
- <;%= %>;、<;% %>;、<;%@ %>;和<;%# %>;的区别
- API--ResponseBody-类
- 2017-2018-2 20165306 实验四《Android开发基础》实验报告
- 八 xml模块
- Zabbix配置优化
- POJ 2752 Seek the Name, Seek the Fame(KMP中next的理解)题解
- 我在JS上解惑之路1
- 【arc102E】Stop. Otherwise...
- [Z3001] connection to database &#39;zabbix&#39; failed: [1045] Access denied for user &#39;zabbix&#39;@&#39;localhost&#39; (using password: YES)
- Python使用SMTP模块、email模块发送邮件
- centos7下只需两个命令升级php版本
热门文章
- intelliJ idea运行新的test功能时,报错:class not found ";....."; empty test suite
- Rep Invariant and Abstraction Function
- 33.Qt模型与视图
- 【翻译】前景img-sprites, 高对比模式分析
- 使用最新vue_cli+webpack搭建的模版
- 【转】javascript 小数乘法结果错误处理
- webpack——打包JS
- BZOJ 4012 [HNOI2015]开店 (树分治+二分)
- 二、frps 完整配置文件
- PHP算法之四大基础算法