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

	}
}
相关推荐
赵师的工作日5 小时前
MongoDB-从0到1-安全管理
数据库·安全·mongodb
Jinkxs5 小时前
MongoDB - MongoDB处理大文件:GridFS的使用场景与教程
数据库·mongodb
林抒5 小时前
(2025版)MongoDB 8.0.13 版本安装与配置(Windows 版)保姆级教程
windows·mongodb·nosql数据库
云边有个稻草人5 小时前
不用公网 IP 也能远程管 MongoDB?本地部署 + cpolar实用方案
网络协议·mongodb·cpolar
铃汐留5 小时前
MongoDB设置密码并使用MongoDB Compass连接
数据库·mongodb
前端fighter12 小时前
全栈项目:校友论坛系统
vue.js·mongodb·node.js
白狐_79815 小时前
基于 MySQL + MongoDB 的在线考试系统数据库设计与实现
数据库·mysql·mongodb
就是蠢啊15 小时前
51单片机——串口通信(二)
嵌入式硬件·mongodb·51单片机
o***111416 小时前
在SpringBoot项目中集成MongoDB
spring boot·后端·mongodb
这人很懒没留下什么1 天前
SpringBoot2.7.4整合MongoDb
数据库·spring boot·mongodb