MangoDB

概述

MangoDB具有高性能、高存储、数据具有结构性的特点。

与Mysql相比,他的性能更高;与Redis相比,他的数据更有结构性

应用场景:数据量较大,要求加载数据快

环境配置

  1. 拉取镜像
sh 复制代码
docker pull mango
  1. 创建容器
sh 复制代码
docker run -di --name mongo-service --restart=always -p 27017:27017 -v /data/mongodata:/data mongo
  1. 导入依赖
xml 复制代码
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
  1. 配置文件
yml 复制代码
spring: 
	data:
		mongodb: 
			host: 192.168.133.128
			port: 27017
			database: DatabaseName
  1. 创建映射
    将实体映射到MangoDB的集合,类似将实体映射到Mysql的表
java 复制代码
@Document("ap_associate_words")
public class ApAssociatewords implements Serializable{
	private static final long serialVersionUID = 1L;
	
	private String id;
	/**
	 * 联想词
	 */
	private String associatewords;
	
	/**
	 * 创建时间
	 */
	private Date createdTime;
}
  1. 示例代码
java 复制代码
public class MangoDemo{
	@Autowired
	MangoTemplate mangoTemplate;

	public void test(){
		//保存或修改(根据ID,有ID就修改,无ID就保存)
		mangoTemplate.save(apAssociatewords);
		
		//根据ID查询集合得到实体
		ApAssociatewords apAssociatewords = mongoTemplate.findById("5fc2fc3fb60c9a039c44556e",ApAssociatewords.class);

		//根据条件去查询实体
		Query query = Query.query(Criteria.where("associatewords").is("测试字段")).with(Sort.by(Sort.Direction.DESC,"createdTime"));
		List<ApAssociatewords apAssociatewordsList = mongoTemplate.find(query, ApAssociateWords.class);

		//根据条件删除文档
		mongoTemplate.remove(Query.query(Criteria.where("associatewords").is("测试字段")),ApAssociateMords.class);

	}
}
相关推荐
xq5148632 天前
Linux系统下安装mongodb
linux·mongodb
程序员拂雨2 天前
MongoDB知识框架
数据库·mongodb
半新半旧2 天前
mongodb 学习笔记
笔记·学习·mongodb
双叶8364 天前
(51单片机)LCD显示红外遥控相关数字(Delay延时函数)(LCD1602教程)(Int0和Timer0外部中断教程)(IR红外遥控模块教程)
c语言·数据库·c++·单片机·嵌入式硬件·mongodb·51单片机
bing_1584 天前
Spring Boot 中 MongoDB @DBRef注解适用什么场景?
spring boot·后端·mongodb
Austindatabases4 天前
给阿里云MongoDB 的感谢信 !!成本降低80%
数据库·mongodb·阿里云·云计算
bing_1584 天前
Spring Boot 中如何启用 MongoDB 事务
spring boot·后端·mongodb
大数据魔法师4 天前
MongoDB(六) - Studio 3T 基本使用教程
mongodb·nosql
micromicrofat5 天前
mongodb升级、改单节点模式
数据库·mongodb
卓越进步5 天前
1、mongodb-- BSON 学习和JSON性能对比
学习·mongodb·json