簡(jiǎn)單介紹
?MongoDB是一個(gè)開(kāi)源、高性能、無(wú)模式的文檔型數(shù)據(jù)庫(kù)。NoSQL數(shù)據(jù)庫(kù)產(chǎn)品中的一種,是最想關(guān)系型數(shù)據(jù)庫(kù)的非關(guān)系型數(shù)據(jù)庫(kù)
應(yīng)用場(chǎng)景
安裝與啟動(dòng)
?直接將安裝的壓縮包進(jìn)行解壓,然后在創(chuàng)建一個(gè)data文件夾,在data文件夾下面創(chuàng)建一個(gè)子文件夾db
啟動(dòng)服務(wù)端 創(chuàng)建數(shù)據(jù)庫(kù)
mongod --dbpath=…\data\db
進(jìn)入bin目錄下面 cmd回車
啟動(dòng)客戶端,直接使用mongo 默認(rèn)服務(wù)器地址和端口號(hào)
但是命令行操作不夠直觀,也不是很方便,直接使用客戶端軟件操作robot3d
創(chuàng)建一個(gè)新的連接
基礎(chǔ)操作
-
創(chuàng)建一個(gè)表book
-
新增一個(gè)數(shù)據(jù)
db.book.save({"name":"springboot"})
- 查詢表中的所有數(shù)據(jù)
db.getCollection('book').find({})
- 待條件的查詢
db.book.find({name:"springboot"})
- 更新操作
db.book.update({name:"springboot"},{$set:{name:"springboot2222"}})
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-478124.html
SpringBoot整合MongoDB
- 創(chuàng)建工程,記得勾選依賴
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-478124.html
- 添加相關(guān)配置內(nèi)容 連接創(chuàng)建的數(shù)據(jù)庫(kù)
spring:
data:
mongodb:
uri: mongodb://localhost/itheima
- 在測(cè)試類中進(jìn)行測(cè)試
package com.example;
import com.example.domain.Book;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
import java.util.List;
@SpringBootTest
class Mongo1ApplicationTests {
@Autowired
private MongoTemplate mongoTemplate;
@Test
void contextLoads() {
Book book = new Book();
book.setId(2);
book.setName("dcnjuasdbc");
book.setType("dcnjuasdbc");
book.setDescription("dcnjuasdbc");
// 使用mongoDB的API 存儲(chǔ)數(shù)據(jù)
mongoTemplate.save(book);
}
@Test
void find(){
List<Book> all = mongoTemplate.findAll(Book.class);
System.out.println(all);
}
}
到了這里,關(guān)于MongoDB簡(jiǎn)單快速入門的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!