Mongo單個數據修改MongoTemplate ///
阿新 • • 發佈:2018-12-17
- @Resource
- protected MongoTemplate mongoTemplate = null;
- //MongoRepository 對個單個數據無法修改 報錯
- @Test
- public void test() {
- UserDO userDO = new UserDO();
-
- userDO.setPhone("12345611324");
- userDO.setSex(2);
- userDO.setBirthday(new Date());
- userDO.setName("hahahahahahha ");
- userDO.setAvator("asdfasfasd");
- userDO.setGmtCreate(new Date());
- userDO.setGmtModified(new Date());
- UserDO save = userRepository.save(userDO);
- System.out.println(save);
- }
- /**
- * mongo單個欄位修改
- *
- * @return void
- */
- @Test
- public void edit() {
- Query query = Query.query(Criteria.where("user_id").is("1"));
- Update update = new Update();
- update.set("name", "飛灑的減肥哈市的開獎號");
- WriteResult user = mongoTemplate.updateFirst(query, update, UserDO.class);
- System.out.println(user);
- }