mongotemplate 简单使用

  怎么说呢,工作需要,不可能给你慢慢学的时间,一切以先解决当前jira为前提, mondb 安装不说了网上一搜就有,推荐图形管理界面 robo3t 比较直观

 

1.多条件查询这个比较简单

  有两种方法

  1Criteria.where("company_code").is(corpCode).and("emp_id").in(empIdArray)这种写法

  2Criteria criatira = new Criteria();

   criatira.andOperator(Criteria.where("userName").is("admin"), Criteria.where("password").is("f818fa8cf51ca364f367f0046bd014ff"));
  推荐第一中简单明了
 
2,删除多条数据
  

Query query = Query.query(Criteria.where("company_code").is(corpCode).and("emp_id").in(empIdArray));
//删除department_code
Update updateDepartmentCode = new Update();
updateDepartmentCode.pullAll("department_code", deptArray.toArray());
mongoTemplate.updateMulti(query, updateDepartmentCode, Constants.MONGOBD_EMPLOYEE_COLLECTION_BEGIN + corpCode.toUpperCase());

//查询并删除department
Update updateDepartment = new Update();
List<JSONObject> deptList = esDepartmentService.checkAndFindDepartment(corpCode, deptArray);
updateDepartment.pullAll("department", deptList.toArray());
mongoTemplate.updateMulti(query, updateDepartment, Constants.MONGOBD_EMPLOYEE_COLLECTION_BEGIN + corpCode.toUpperCase());

 

3增加多条数据

Query query = Query.query(Criteria.where("company_code").is(corpCode).and("emp_id").in(empIdArray));
//删除department_code
Update updateDepartmentCode = new Update();
updateDepartmentCode.pullAll("department_code", deptArray.toArray());
mongoTemplate.updateMulti(query, updateDepartmentCode, Constants.MONGOBD_EMPLOYEE_COLLECTION_BEGIN + corpCode.toUpperCase());

//查询并删除department
Update updateDepartment = new Update();
List<JSONObject> deptList = esDepartmentService.checkAndFindDepartment(corpCode, deptArray);
updateDepartment.pullAll("department", deptList.toArray());
mongoTemplate.updateMulti(query, updateDepartment, Constants.MONGOBD_EMPLOYEE_COLLECTION_BEGIN + corpCode.toUpperCase());

 

4同一个update对象不能多次使用,后面的条件会覆盖掉前面的数据。

 

 

posted @ 2018-05-25 16:35  cheakceep  阅读(1813)  评论(0编辑  收藏  举报