https://yq.aliyun.com/articles/134279#
http://www.yiibai.com/mongodb/mongodb_create_database.html
http://blog.csdn.net/yu757371316/article/details/55210536
https://www.cnblogs.com/chenlq/p/6515876.html
其他
http://blog.csdn.net/congcong68/article/details/47357203
http://blog.csdn.net/u012150370/article/details/518227
解决方案
http://xiaofancn.iteye.com/blog/1163200
http://xiaoqiangge.com/aritcle/1501040086286.html
/** * @param req * @param res * @return */ @ResponseBody @GetMapping(value = "/article") public Integer createUser(HttpServletRequest req, HttpServletResponse res, Article record) throws RestfulAPIException { try { List<String> tags = new LinkedList<>(); for(int i = 0;i < 20;i++) { tags.add("tagname" + i); } mongoTemplate.save(new Tag("2015265", "张三", tags.toArray(new String[tags.size()]))); //mongoTemplate. updateMulti (new Query(Criteria.where("id").is("2015265")), new Update().set("date", "2015-08-08"), "tag"); return 0; } catch (BusinessException e) { throw new RestfulAPIException(e.getCode(), e.getMsg()); } catch (Exception e) { throw new RestfulAPIException(ResponseCode.MISSING_REQUIRED_PARAMS.getCode(), e.getClass() + " : " + e.getMessage()); } } /** * @param req * @param res * @return */ @ResponseBody @GetMapping(value = "/update") public Integer updateTag(HttpServletRequest req, HttpServletResponse res, Article record) throws RestfulAPIException { try { List<String> tags = new LinkedList<>(); for(int i = 0;i < 20;i++) { tags.add("tagname" + i); } //mongoTemplate. updateMulti (new Query(Criteria.where("name").is("张三")), new Update().set("date", "2015-08-08"), "tag"); //mongoTemplate. updateMulti (new Query(Criteria.where("name").is("张三")), new Update().set("tag2", tags.toArray(new String[tags.size()])), "tag"); //mongoTemplate. updateMulti (new Query(Criteria.where("name").is("张三")), new Update().set("tag2.0", "总监级别"), "tag"); mongoTemplate. updateMulti (new Query(Criteria.where("name").is("张三")), new Update().push("tag2", "总监级别"), "tag"); return 0; } catch (BusinessException e) { throw new RestfulAPIException(e.getCode(), e.getMsg()); } catch (Exception e) { throw new RestfulAPIException(ResponseCode.MISSING_REQUIRED_PARAMS.getCode(), e.getClass() + " : " + e.getMessage()); } }
# spring.data.mongodb.host=127.0.0.1 spring.data.mongodb.port=27017 spring.data.mongodb.database=kth
package key.to.happiness.model; import org.springframework.data.mongodb.core.mapping.Document; import javax.persistence.Entity; import java.io.Serializable; @Entity @Document(collection = "tag") public class Tag implements Serializable { private String id; private String name; private String sex; private Integer age; private String[] tags; @Override public String toString() { return "tag [name=" + name + ", sex=" + sex + ", age=" + age + "]"; } public Tag(String id, String name, String[] tags) { super(); this.id = id; this.name = name; this.tags = tags; } }