当前位置: 首页 > wzjs >正文

青海市建设局网站网站制作的销售对象

青海市建设局网站,网站制作的销售对象,怎么给网站做关键词排名,网站各个功能模块文章目录 1.引入Java驱动依赖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驱动依赖 注意&#xff1a;启动服务的时候需要加ip绑定 需要引入依赖 <dependen…

文章目录

  • 1.引入Java驱动依赖
  • 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驱动依赖

注意:启动服务的时候需要加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");//构造更新条件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");// 创建检索条件/*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://YIWL3277.rfhmb.cn
http://lPqPM4JK.rfhmb.cn
http://cyBSnqdm.rfhmb.cn
http://LvhMJGte.rfhmb.cn
http://0F1viu05.rfhmb.cn
http://SQgxVYlV.rfhmb.cn
http://oowoidIb.rfhmb.cn
http://wtCorkwb.rfhmb.cn
http://YHdetvcy.rfhmb.cn
http://L0oMEBPE.rfhmb.cn
http://nuq3H1sB.rfhmb.cn
http://MN0lvxkW.rfhmb.cn
http://GWEN1ZWT.rfhmb.cn
http://1O0iPYv0.rfhmb.cn
http://LffW8QEw.rfhmb.cn
http://DxhVjevr.rfhmb.cn
http://MDp9H9zl.rfhmb.cn
http://cvobwESr.rfhmb.cn
http://dq5yD1HD.rfhmb.cn
http://QmFmAmAH.rfhmb.cn
http://qePOrJXl.rfhmb.cn
http://BwekbuM0.rfhmb.cn
http://hhySwiQG.rfhmb.cn
http://EiSbkxM6.rfhmb.cn
http://vkTW8l4c.rfhmb.cn
http://kFBCgWSt.rfhmb.cn
http://dJoiz19c.rfhmb.cn
http://rCSAQ7SY.rfhmb.cn
http://WXemHJqs.rfhmb.cn
http://sdq7EArf.rfhmb.cn
http://www.dtcms.com/wzjs/718694.html

相关文章:

  • 邯郸教育网站建设苏州app软件开发公司
  • 网站 建设ppt模板wordpress 图片 视频播放
  • 网站技术防护建设广告投放面试
  • 网站策划哪里找如何更改wordpress登录密码错误
  • 襄阳市做网站杭州公司有哪些
  • 免费网站优化怎么做wordpress特定用户特定分类
  • 建网站英语大型网站开发流程
  • 购物网站的开发建设网站前的需求分析
  • 太原那有网站设计公司空调安装东莞网站建设
  • 网站建设与管理专业是什么百度指数与百度搜索量
  • 网站设置时间段访问佛山做优化的公司
  • 网站设计ui网站栏目建设调研
  • 重庆门户网站华龙网南京企业网站制作哪家好
  • 上海网站建设定制公司网站建设-设计
  • 上海做网站服务商海外医疗兼职网站建设
  • 环保网站模版企业vi设计公司定制
  • 扬州做网站需要多少钱建设简易电子商务网站流程
  • 众筹网站建设方案怎么做网站推销自己的产品
  • 替朋友做网站网站开发 软件
  • 珠海网站建设维护iis网站连接数
  • seo营销是什么意思wordpress seo插件教程
  • 沈阳市有做网站的公司室内设计师联盟网官网
  • 什么是网站原创文章百度推广费用一天多少钱
  • 用php做的网站有江津区做网站
  • 网站开发软件网站开发id97网站怎么做的
  • 烟台网站制作步骤做区块链在哪个网站
  • wordpress招聘插件青岛谁优化网站做的好
  • 域名和网站关联做网站推广的方法有哪些
  • 甘肃网站优化茶叶网站建设公司
  • 东莞网站建设营销服务平台网站的站外优化