mongoTemplate.getCollection方法返回值问题

来源:互联网 发布:守望先锋amd优化设置 编辑:程序博客网 时间:2024/06/01 22:37

今天参考网上MongoDB的例子(https://www.cnblogs.com/wenbronk/p/6385935.html)写了个demo,发现MongoTemplate的getCollection方法返回值和例子上的不一样,就在想是不是版本的问题,然后就去翻了官方的API文档,发现这个方法,在1.9.x的时候还是com.mongodb.DBCollection类型,2.0以后就改成了com.mongodb.client.MongoCollection的类型,下面贴上两个版本的API参考下


MongoTemplate


版本:1.9.x及之前(https://docs.spring.io/spring-data/data-mongo/docs/1.9.x/api/)


public com.mongodb.DBCollection getCollection(String collectionName)
Description copied from interface: MongoOperations
Get a collection by name, creating it if it doesn't exist.

Translate any exceptions as necessary.

Specified by:
getCollection in interface MongoOperations
Parameters:
collectionName - name of the collection
Returns:

an existing collection or a newly created one.


版本:2.0.0及之后(https://docs.spring.io/spring-data/data-mongo/docs/2.0.0.BUILD-SNAPSHOT/api/)

public com.mongodb.client.MongoCollection<org.bson.Document> getCollection(String collectionName)
Description copied from interface: MongoOperations
Get a collection by name, creating it if it doesn't exist.

Translate any exceptions as necessary.

Specified by:
getCollection in interface MongoOperations
Parameters:
collectionName - name of the collection. Must not be null.
Returns:
an existing collection or a newly created one.


是不是DBCollection这个类有什么bug,后来在版本升级的时候改变了方法的返回类型?

原创粉丝点击