增删改数据
//增加数据 db.book.save({"name":"springboot"}) //增加数据 db.book.save({"name":"springboot","type":"springboot"}) //删除数据 db.book.remove({"type":"springboot"}) //更新数据 db.book.update({name:"springboot"},{$set:{name:"springboot2"}})
查询
db.book.find()
整合
勾选Mongodb
写配置文件 – 这个必须配置一下,她没有内置
spring: data: mongodb: uri: mongodb://localhost/itheima
测试
@SpringBootTest class Springboot17MongodbApplicationTests { @Autowired private MongoTemplate mongoTemplate; @Test void contextLoads() { Book book = new Book(); book.setId(1); book.setName("springboot"); book.setType("springboot"); book.setDescription("springboot"); mongoTemplate.save(book); } }