Reading of DBname.system.indexes failed on Atlas cluster by mongobee after getting connected

一世执手 提交于 2019-12-02 02:53:00

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

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());
    }

}
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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!