mongodb的java驱动_Java访问MongoDB:安装驱动

引用

原帖收藏于IT老兵驿站。

前言

Spring项目中可能需要用到MongoDB,要了解一下Java项目如何连接MongoDB,查了查google,对比了一下,发现官网的讲解非常清楚,这样的话,直接阅读官网,效率是最高的。

本文捡着最主要的地方做一下笔记,方便自己学习,也输出一下,这样输出的速度也快,也可以方便他人借鉴,但不再全文翻译,那样输出太慢,而且个人感觉,只是方便了懒人,学习计算机,不提高英文,永远是短一条腿走路,很难达到很高的水平。

Installation

The recommended way to get started using one of the drivers in your project is with a dependency management system.

There are two Maven artifacts available in the release. The preferred artifact for new applications is mongodb-driver-sync however, we still publish the legacy mongo-java-driver uber-jar as well as the mongodb-driver jar introduced in 3.0.

Java的MongoDB驱动当前一共有4个库,先需要搞清楚这4个库的关系,优先推荐mongodb-driver-sync。

MongoDB Driver Sync

The MongoDB Driver mongodb-driver-sync is the synchronous Java driver containing only the generic MongoCollection interface that complies with a new cross-driver CRUD specification. It does not include the legacy API (e.g. DBCollection).

这个库只有MongoCollection接口,并且不包含废弃的API。

IMPORTANT

This is a Java 9-compliant module with an Automatic-Module-Name of org.mongodb.driver.sync.client.

The mongodb-driver-sync artifact is a valid OSGi bundle whose symbolic name is org.mongodb.driver-sync.

这块有点没明白,似乎是分成了两个包,一个是兼容Java 9的org.mongodb.driver.sync.client和遵循OSGi的org.mongodb.driver-sync。

下面是Maven的配置,原帖中还有Gradle的配置方式。

org.mongodb

mongodb-driver-sync

3.9.1

Note: You can also download the mongodb-driver-sync jar directly from sonatype.

If downloading mongodb-driver-sync manually, you must also download its dependencies: bson and mongodb-driver-core

当然,你可以可以直接从sonatype下载jar包,如果那样的话,你需要还下载一下依赖。

MongoDB Driver Legacy

The MongoDB Legacy driver mongodb-driver-legacy is the legacy synchronous Java driver whose entry point is com.mongodb.MongoClient and central classes include com.mongodb.DB, com.mongodb.DBCollection, and com.mongodb.DBCursor.

这个mongodb-driver-legacy驱动带有com.mongodb.MongoClient这个入口,核心类是com.mongodb.DB, com.mongodb.DBCollection和com.mongodb.DBCursor,很多网上的样例用的是这两个类。

IMPORTANT

While not deprecated, we recommend that new applications depend on the mongodb-driver-syncmodule.

org.mongodb

mongodb-driver-legacy

3.9.1

Note: You can also download the mongodb-driver-legacy jar directly from sonatype.

If downloading mongodb-driver-legacy manually, you must also download its dependencies: bson andmongodb-driver-core

MongoDB Driver

The MongoDB Driver mongodb-driver is the updated synchronous Java driver that includes the legacy API as well as a new generic MongoCollection interface that complies with a new cross-driver CRUD specification.

mongodb-driver是更新的同步化的Java驱动,包含旧的API,也包含新的MongoCollection接口。(这个应该是为了过渡考虑)

IMPORTANT

mongodb-driver is not an OSGi bundle: both mongodb-driver and mongodb-driver-core, a dependency of mongodb-driver, include classes from the com.mongodb package.

For OSGi-based applications, use the mongodb-driver-sync or the mongo-java-driver uber jar instead.

It is also not a Java 9 module.

This module is deprecated and will no longer be published in the next major release of the driver (4.0).

org.mongodb

mongodb-driver

3.9.1

Note: You can also download the mongodb-driver jar directly from sonatype.

If downloading mongodb-driver manually, you must also download its dependencies: bson and mongodb-driver-core

Uber Jar (Legacy)

For new applications, the preferred artifact is mongodb-driver-sync; however, the legacy mongo-java-driver uber jar is still available. The uber jar contains: the BSON library, the core library, and the mongodb-driver.

uber jar这个包是很老的包,但是还是可以用。

NOTE

This is a Java 9-compliant module with an Automatic-Module-Name of org.mongodb.driver.sync.client.

The mongo-java-driver artifact is a valid OSGi bundle whose symbolic name is org.mongodb.mongo-java-driver.

IMPORTANT

This module is deprecated and will no longer be published in the next major release of the driver (4.0).

org.mongodb

mongo-java-driver

3.9.1

Note: You can also download the mongo-java-driver jar directly from sonatype.

参考

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值