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结束...............");
}
}

最新文章

  1. git提交项目到已存在的远程分支
  2. python的内存管理机制
  3. 【opencv学习笔记】SetImageROI函数设置ROI区域的作用及用法
  4. C++ Primer:第七章:类
  5. 【和我一起学python吧】Python安装、配置图文详解
  6. Python自动化运维之27、Django(一)
  7. ●BOZJ 3144 [Hnoi2013]切糕
  8. linux子系统折腾记 (二)
  9. Linux编译静态库与共享库
  10. &lt;%= %&gt;、&lt;% %&gt;、&lt;%@ %&gt;和&lt;%# %&gt;的区别
  11. API--ResponseBody-类
  12. 2017-2018-2 20165306 实验四《Android开发基础》实验报告
  13. 八 xml模块
  14. Zabbix配置优化
  15. POJ 2752 Seek the Name, Seek the Fame(KMP中next的理解)题解
  16. 我在JS上解惑之路1
  17. 【arc102E】Stop. Otherwise...
  18. [Z3001] connection to database &#39;zabbix&#39; failed: [1045] Access denied for user &#39;zabbix&#39;@&#39;localhost&#39; (using password: YES)
  19. Python使用SMTP模块、email模块发送邮件
  20. centos7下只需两个命令升级php版本

热门文章

  1. intelliJ idea运行新的test功能时,报错:class not found &quot;.....&quot; empty test suite
  2. Rep Invariant and Abstraction Function
  3. 33.Qt模型与视图
  4. 【翻译】前景img-sprites, 高对比模式分析
  5. 使用最新vue_cli+webpack搭建的模版
  6. 【转】javascript 小数乘法结果错误处理
  7. webpack——打包JS
  8. BZOJ 4012 [HNOI2015]开店 (树分治+二分)
  9. 二、frps 完整配置文件
  10. PHP算法之四大基础算法