After many attempts and reading, I found a way to get MongoDB 3.0 to work with authentication.
This was a new installation of MongoDB 3.0, without an update.
I used these maven dependencies:
<dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-mongodb</artifactId> <version>1.6.2.RELEASE</version> </dependency> <dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-java-driver</artifactId> <version>3.0.0</version> </dependency>
having a parent
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.2.2.RELEASE</version> </parent>
Then in my configuration file I had
@Bean public MongoDbFactory mongoDbFactory() throws Exception {
And finally, wherever you have access to the MongoTemplate bean, you can do
mongoTemplate.insert(objectToStore, collectionName);
Luca stucchi
source share