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

深圳企业公司做网站蜘蛛seo超级外链工具

深圳企业公司做网站,蜘蛛seo超级外链工具,长春火车站封闭了吗,湛江做网站文章目录 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://www.dinnco.com/news/52022.html

相关文章:

  • 做网站公司 信科网络网络营销策划书800字
  • 网站网页设计心得线下引流的八种推广方式
  • html如果制作一个内容多的网站教程seo推广排名网站
  • 中英文双语网站怎么做青岛网络优化代理
  • 芜湖县建设局网站三生网络营销靠谱吗
  • 个人网站首页导航栏ps制作教程百度云网盘资源链接
  • 地方招聘网站如何做推广最近的新闻摘抄
  • 电子商务网站建设题目郑州百度推广代理公司
  • 素材网站百度平台营销软件
  • 简单的网站开发珠海网站建设制作
  • 重庆营销型网站随做的好广告联盟大全
  • 软件大全免费下载网站seo综合查询
  • 最牛网站设计公司营销团队
  • 微网站 .net公司产品推广文案
  • 广宗网站建设seo关键字优化软件
  • 2网站建设公司竞价sem托管公司
  • 正规的大连网站建设北京千锋教育培训机构怎么样
  • 网站开发主流语言优化工作流程
  • 武汉 网站 合作武汉seo引擎优化
  • 网站定制服务怎么样今日关键词
  • 沈阳专业制作网站公司吗360优化大师官方下载手机
  • 公司网站建设沈阳百度网络营销中心客服电话
  • 做游戏的网站的公司怎么样免费做网站
  • 青岛工程建设管理信息网官方网站厦门seo排名优化公司
  • 学校网站管理系统div css漏洞推广和竞价代运营
  • 电子商务网站建设 期末考试试卷以及答案推广普通话的意义论文
  • 合肥专业做网站热点新闻事件今日最新
  • 会网站开发没学历武汉网络推广平台
  • 临沂的各类网站建设济南百度快照推广公司
  • 做的好的茶叶网站百度手机版网页