中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

深圳企業(yè)公司做網(wǎng)站手機優(yōu)化大師下載

深圳企業(yè)公司做網(wǎng)站,手機優(yōu)化大師下載,山東展廳設(shè)計公司,裝潢公司網(wǎng)站設(shè)計與制作文章目錄 1.引入Java驅(qū)動依賴2.快速開始2.1 先在monsh連接建立collection2.2 java中快速開始2.3 Insert a Document2.4 Update a Document2.5 Find a Document2.6 Delete a Document 1.引入Java驅(qū)動依賴 注意&#xff1a;啟動服務(wù)的時候需要加ip綁定 需要引入依賴 <dependen…

文章目錄

  • 1.引入Java驅(qū)動依賴
  • 2.快速開始
    • 2.1 先在monsh連接建立collection
    • 2.2 java中快速開始
    • 2.3 Insert a Document
    • 2.4 Update a Document
    • 2.5 Find a Document
    • 2.6 Delete a Document

1.引入Java驅(qū)動依賴

注意:啟動服務(wù)的時候需要加ip綁定
需要引入依賴

<dependency><groupId>org.mongodb</groupId><artifactId>mongodb-driver-sync</artifactId><version>5.1.0</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency><!-- https://mvnrepository.com/artifact/org.mongodb/bson --><dependency><groupId>org.mongodb</groupId><artifactId>bson</artifactId><version>5.1.0</version></dependency><!-- https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-core --><dependency><groupId>org.mongodb</groupId><artifactId>mongodb-driver-core</artifactId><version>5.1.0</version></dependency>

2.快速開始

2.1 先在monsh連接建立collection

db.players.insertOne({name:"palyer1",height:181,weigh:90})
{acknowledged: true,insertedId: ObjectId('665c5e0a522ef6dba6a26a13')
}
test> db.players.insertOne({name:"palyer2",height:190,weigh:100})
{acknowledged: true,insertedId: ObjectId('665c5e18522ef6dba6a26a14')
}
test> db.players.find()
[{_id: ObjectId('665c5e0a522ef6dba6a26a13'),name: 'player1',height: 181,weigh: 90},{_id: ObjectId('665c5e18522ef6dba6a26a14'),name: 'player2',height: 190,weigh: 100}
]

2.2 java中快速開始

public class QuickStart {public static void main(String[] args) {// 連接的urlString uri = "mongodb://node02:27017";try (MongoClient mongoClient = MongoClients.create(uri)) {MongoDatabase database = mongoClient.getDatabase("test");MongoCollection<Document> collection = database.getCollection("players");Document doc = collection.find(eq("name", "palyer2")).first();if (doc != null) {//{"_id": {"$oid": "665c5e18522ef6dba6a26a14"}, "name": "palyer2", "height": 190, "weigh": 100}System.out.println(doc.toJson());} else {System.out.println("No matching documents found.");}}}}

2.3 Insert a Document

 @Testpublic void InsertDocument(){MongoDatabase database = mongoClient.getDatabase("test");MongoCollection<Document> collection = database.getCollection("map");try {// 插入地圖文檔InsertOneResult result = collection.insertOne(new Document().append("_id", new ObjectId()).append("name", "beijing").append("longitude", "40°N").append("latitude", "116°E"));//打印文檔的id//Success! Inserted document id: BsonObjectId{value=665c6424a080bb466d32e645}System.out.println("Success! Inserted document id: " + result.getInsertedId());// Prints a message if any exceptions occur during the operation} catch (MongoException me) {System.err.println("Unable to insert due to an error: " + me);}

2.4 Update a Document

 @Testpublic void UpdateDocument(){MongoDatabase database = mongoClient.getDatabase("test");MongoCollection<Document> collection = database.getCollection("map");//構(gòu)造更新條件Document query = new Document().append("name",  "beijing");// 指定更新的字段Bson updates = Updates.combine(Updates.set("longitude", "40.0N"),Updates.set("latitude", "116.0E"));// Instructs the driver to insert a new document if none match the queryUpdateOptions options = new UpdateOptions().upsert(true);try {// 更新文檔UpdateResult result = collection.updateOne(query, updates, options);// Prints the number of updated documents and the upserted document ID, if an upsert was performedSystem.out.println("Modified document count: " + result.getModifiedCount());System.out.println("Upserted id: " + result.getUpsertedId());} catch (MongoException me) {System.err.println("Unable to update due to an error: " + me);}}

2.5 Find a Document

 @Testpublic void testFindDocuments(){MongoDatabase database = mongoClient.getDatabase("test");MongoCollection<Document> collection = database.getCollection("map");// 創(chuàng)建檢索條件/*Bson projectionFields = Projections.fields(Projections.include("name", "shanghai"),Projections.excludeId());*/// 匹配過濾檢索文檔MongoCursor<Document> cursor = collection.find(eq("name", "shanghai"))//.projection(projectionFields).sort(Sorts.descending("longitude")).iterator();// 打印檢索到的文檔try {while(cursor.hasNext()) {System.out.println(cursor.next().toJson());}} finally {cursor.close();}}

檢索

2.6 Delete a Document

 @Testpublic void DeleteDocument(){MongoDatabase database = mongoClient.getDatabase("test");MongoCollection<Document> collection = database.getCollection("map");Bson query = eq("name", "shanghai");try {// 刪除名字為shanghai的地圖DeleteResult result = collection.deleteOne(query);System.out.println("Deleted document count: " + result.getDeletedCount());// 打印異常消息} catch (MongoException me) {System.err.println("Unable to delete due to an error: " + me);}}
http://www.risenshineclean.com/news/48246.html

相關(guān)文章:

  • 權(quán)重域名做網(wǎng)站有用么培訓(xùn)機構(gòu)是干什么的
  • 企業(yè)網(wǎng)絡(luò)營銷實施方案seo優(yōu)化前景
  • 有什么免費的wordpresswindows優(yōu)化大師是系統(tǒng)軟件嗎
  • 有什么網(wǎng)站可以接設(shè)計做網(wǎng)站運營需要多少錢
  • 怎樣做網(wǎng)站的鏈接百度競價優(yōu)缺點
  • 企業(yè)的所得稅費用怎么算沈陽關(guān)鍵字優(yōu)化公司
  • 學(xué)校網(wǎng)站建設(shè)計劃湖南專業(yè)關(guān)鍵詞優(yōu)化服務(wù)水平
  • 建設(shè)購物網(wǎng)站的條件百度競價推廣代運營公司
  • 網(wǎng)頁設(shè)置如何優(yōu)化百度seo排名
  • 溫州做網(wǎng)站掌熊號seo網(wǎng)站查詢
  • 丹陽做公司網(wǎng)站sem優(yōu)化師
  • 常州網(wǎng)站設(shè)計湛江公司電話網(wǎng)絡(luò)營銷推廣的基本手段
  • 辦公門戶網(wǎng)站模板簡單的網(wǎng)頁設(shè)計
  • 家庭網(wǎng)絡(luò)做網(wǎng)站站長工具seo綜合查詢廣告
  • 蘭州優(yōu)化網(wǎng)站媒體資源網(wǎng)
  • 深圳裝修公司網(wǎng)站熱點新聞事件素材
  • 贛州網(wǎng)站建設(shè)聯(lián)系方式寧德市地圖
  • 游戲抽獎網(wǎng)站用java怎么做北京朝陽區(qū)
  • 搭建網(wǎng)站程序網(wǎng)站點擊量與排名
  • 網(wǎng)站代碼多彩經(jīng)典模板網(wǎng)站建設(shè)
  • 企業(yè)網(wǎng)站只做英文網(wǎng)站搜什么關(guān)鍵詞
  • 服務(wù)器上如何做網(wǎng)站電商運營seo
  • 尋找武漢手機網(wǎng)站建設(shè)精準(zhǔn)引流推廣公司
  • 網(wǎng)站建設(shè)字體顏色代碼網(wǎng)絡(luò)推廣外包業(yè)務(wù)銷售
  • 網(wǎng)店代理靠譜嗎鄭州好的seo外包公司
  • 廈門網(wǎng)頁網(wǎng)絡(luò)營銷優(yōu)化推廣公司
  • 怎么做專門賣二手衣服的網(wǎng)站域名批量查詢工具
  • 深圳網(wǎng)站(建設(shè)信科網(wǎng)絡(luò))seo云優(yōu)化外包
  • 網(wǎng)站租空間多少錢一年青島網(wǎng)絡(luò)優(yōu)化費用
  • 如何搭建一個屬于自己的網(wǎng)站陜西seo主管