VERGiL
VERGiL

Reputation: 31

MongoDB GridFS authentication not working

I am trying to insert data to a MongoDB 3.4 GridFS storage with enabled authentication via a Spring Boot app, but I keep getting this error:

Query failed with error code 13 and error message 'not authorized on user to execute command { find: \"fs.files\", filter: { metadata.fieldname: \"someContent\" } }' on server ip:27017"

I created a user with "superuser" rights for this:

use admin
db.createUser(
{
   user: "admin", 
   pwd: "password", 
   roles:["root"]
})

My spring boot application.properties are:

spring.data.mongodb.host=ip
spring.data.mongodb.port=27017
spring.data.mongodb.username=admin
spring.data.mongodb.password=password
spring.data.mongodb.database=user
spring.data.mongodb.authentication-database=admin

I already tried the "old" MongoDB roles with no luck:

db.createUser(
{
   user: "admin",
   pwd: "password",
   roles: [
             { role: "userAdminAnyDatabase", db: "admin" },
             { role: "readWriteAnyDatabase", db: "admin" },
             { role: "dbAdminAnyDatabase", db: "admin" },
             { role: "clusterAdmin", db: "admin" }
          ]
})

Reading and writing to other (non-gridFS) databases works perfectly. Any ideas on how to solve this?

Upvotes: 2

Views: 941

Answers (1)

VERGiL
VERGiL

Reputation: 31

Solution: I still had an AbstractMongoConfiguration class lying around.

@Configuration
public class SpringMongoConfig extends AbstractMongoConfiguration {
  //some code...
}

Deleting it solved it. You have to either use application.properties OR a java class for MongoDB configuration.

Upvotes: 1

Related Questions