mongotemplate 簡單使用

  怎麼說呢,工做須要,不可能給你慢慢學的時間,一切以先解決當前jira爲前提, mondb 安裝不說了網上一搜就有,推薦圖形管理界面 robo3t 比較直觀java

 

1.多條件查詢這個比較簡單code

  有兩種方法對象

  1Criteria.where("company_code").is(corpCode).and("emp_id").in(empIdArray)這種寫法blog

  2Criteria criatira = new Criteria();string

   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());it

 

3增長多條數據class

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());date

 

4同一個update對象不能屢次使用,後面的條件會覆蓋掉前面的數據。List

相關文章
相關標籤/搜索