4

I have a Jhipster Spring boot project. Recently I shifted from mlabs standalone sandboxes to Atlas cluster sandbox M0 Free tier replica set. It even worked and I had made some database operations on it. But now for some reason then there is a read permission error

Error creating bean with name 'mongobee' defined in class path resource [DatabaseConfiguration.class]: Invocation of init method failed; nested exception is com.mongodb.MongoQueryException: Query failed with error code 8000 and error message 'user is not allowed to do action [find] on [test.system.indexes]' on server ********-shard-00-01-mfwhq.mongodb.net:27017

You can see the full stack here https://pastebin.com/kaxcr7VS

I have searched high and low and all I could find is that M0 tier user doesn't have permissions to overwrite admin database which I am not doing.

Even now connection to Mlabs DB works fine but have this issue on Atlas DB M0 tier.

Mongo DB version : 3.4

Jars and It's version name: 'mongobee', version: '0.10' name: 'mongo-java-driver', version: '3.4.2'

@Neil Lunn The userId I am using to connect is that of admin's and the connection read and write works through shell or Robo3T(mongo client)

M. Justin
  • 14,487
  • 7
  • 91
  • 130
Artist
  • 93
  • 1
  • 10
  • From the stack trace `'user is not allowed to do action [find] on [test.system.indexes]'` This means the user you are connecting to lacks the permission to do this on the current database. Either you're on the wrong database namespace for the user, or you assigned the wrong permissions to the user. The `readWrite` role should be a reasonable starter for most application usage. – Neil Lunn Apr 23 '18 at 06:25

4 Answers4

9

After discussion with MongoDB support team, MongoDB 3.0 deprecates direct access to the system.indexes collection, which had previously been used to list all indexes in a database. Applications should use db.<COLLECTION>.getIndexes() instead.

From MongoDB Atlas docs it can be seen that they may forbid calls to system. collections:

Optionally, for the read and readWrite role, you can also specify a collection. If you do not specify a collection for read and readWrite, the role applies to all collections (excluding some system. collections) in the database.

From the stacktrace it's visible that MongoBee is trying to make this call, so it's now the library issue and it should be updated.

UPDATE: In order to fix an issue until MongoBee has released new version:

  1. Get the latest sources of MongoBee git clone git@github.com:mongobee/mongobee.git, cd mongobee
  2. Fetch pull request git fetch origin pull/87/head:mongobee-atlas
  3. Checkout git checkout mongobee-atlas
  4. Install MongoBee jar mvn clean install
  5. Get compiled jar from /target folder or local /.m2
  6. Use the jar as a dependency on your project
yyunikov
  • 5,719
  • 2
  • 43
  • 78
  • Even with the latest mongobee jar which is 0.13, it is throwing the same error. How do we resolve this issue so that i can connect to Atlas cluster? any suggestions are appreciated – Artist Apr 23 '18 at 09:08
  • 1
    @Artist I've submitted a pull request to MongoBee library to fix this. I hope they'll merge it and release it soon. https://github.com/mongobee/mongobee/pull/87 – yyunikov Apr 27 '18 at 17:26
  • That's is helpful. Do you recommend overriding the jar class to overcome this issue? – Artist Apr 30 '18 at 08:37
  • @Artist I would rather compile another `jar` with the pull request above, keep in repo and use it until the new library version is released. – yyunikov Apr 30 '18 at 08:38
  • 1
    @Artist I've added detailed steps on what to do, please check it out and accept the answer if it works for you. – yyunikov May 07 '18 at 05:28
  • Mongobee is no longer maintained, so that PR is still open. Projects that require production stability obviously cannot rely on a PR build, but a couple of years ago the mongobee project was forked to [mongock](https://github.com/cloudyrock/mongock), which actually addresses this exact problem. For those worried about the pains of moving from one dependency to another, I just did this in 5 mins with no issues – Daniel Arthur May 09 '20 at 16:18
2

Came across this issue this morning. Heres a quick and dirty monkey-patch for the problem:

package com.github.mongobee.dao;

import com.github.mongobee.changeset.ChangeEntry;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;

import java.util.List;

import static com.github.mongobee.changeset.ChangeEntry.CHANGELOG_COLLECTION;

public class ChangeEntryIndexDao {

    public void createRequiredUniqueIndex(DBCollection collection) {
        collection.createIndex(new BasicDBObject()
                        .append(ChangeEntry.KEY_CHANGEID, 1)
                        .append(ChangeEntry.KEY_AUTHOR, 1),
                new BasicDBObject().append("unique", true));
    }

    public DBObject findRequiredChangeAndAuthorIndex(DB db) {
        DBCollection changelogCollection = db.getCollection(CHANGELOG_COLLECTION);
        List<DBObject> indexes = changelogCollection.getIndexInfo();
        if (indexes == null) return null;
        for (DBObject index : indexes) {
            BasicDBObject indexKeys = ((BasicDBObject) index.get("key"));
            if (indexKeys != null && (indexKeys.get(ChangeEntry.KEY_CHANGEID) != null && indexKeys.get(ChangeEntry.KEY_AUTHOR) != null)) {
                return index;
            }
        }
        return null;
    }

    public boolean isUnique(DBObject index) {
        Object unique = index.get("unique");
        if (unique != null && unique instanceof Boolean) {
            return (Boolean) unique;
        } else {
            return false;
        }
    }

    public void dropIndex(DBCollection collection, DBObject index) {
        collection.dropIndex(index.get("name").toString());
    }

}
  • How can I be able to use the above code, since it is a jar – Artist Apr 24 '18 at 07:02
  • If you put it in your own src/main/java folder under the matching package name com.gitgub.mongobee.dao it will override the jar ;) thus it should be consider a temporary solution! I’ll submit to mongobee for a future consideration – Oliver Oldfield-Hodge Apr 25 '18 at 07:28
  • No worries, if this works for you please consider marking as answered. :) – Oliver Oldfield-Hodge Apr 26 '18 at 13:07
  • this is a nice hack but overriding a jar class is not what I am looking for. If there are no more answers I will mark this as the answer – Artist Apr 27 '18 at 09:03
  • for further searchers, if get any error about loading this class twice (lib and classpath) you might need to exclude the class from mongobee that is loaded. – rodrigocprates May 01 '20 at 18:55
0
Caused by: java.lang.NoSuchMethodError: com.github.mongobee.dao.ChangeEntryIndexDao.<init>(Ljava/lang/String;)V
    at com.github.mongobee.dao.ChangeEntryDao.<init>(ChangeEntryDao.java:34)
    at com.github.mongobee.Mongobee.<init>(Mongobee.java:87)
    at com.xxx.proj.config.DatabaseConfiguration.mongobee(DatabaseConfiguration.java:62)
    at com.xxx.proj.config.DatabaseConfiguration$$EnhancerBySpringCGLIB$$4ae465a5.CGLIB$mongobee$1(<generated>)
    at com.xxx.proj.config.DatabaseConfiguration$$EnhancerBySpringCGLIB$$4ae465a5$$FastClassBySpringCGLIB$$f202afb.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
    at com.xxx.proj.config.DatabaseConfiguration$$EnhancerBySpringCGLIB$$4ae465a5.mongobee(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 22 common frames omitted

jhipster 5 must be using a different version, because i get that when implementing the above code. looks like its expecting a different version.

pronane
  • 248
  • 1
  • 5
  • 10
0

This access to system.indexes is an open issue in mongobee. The issue has been fixed in the project, but the project was abandoned before the fix was ever released.

Due to this project abandonment, two successor libraries have since been forked from mongobee which have fixed this issue: Mongock and mongobeeJ.

Switching your application's dependency from the mongobee library to one of these successor libraries will allow you to run mongobee database migrations on Atlas.

To summarize these libraries:

  • Mongock - Forked from mongobee in 2018. Actively maintained. Has evolved significantly from the original, including built-in support for Spring, Spring Boot, and both versions 3 & 4 of the Mongo Java driver.
  • mongobeeJ - Forked from mongobee in 2018. Five updated versions have been released. Minimal evolution from the original mongobee. Mongo Java Driver 4 support was implemented in August, 2020. This project was deprecated in August, 2020, with a recommendation from its creators to use a library such as Mongock instead.
M. Justin
  • 14,487
  • 7
  • 91
  • 130