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

后端 未结 4 1105
感动是毒
感动是毒 2021-01-20 03:31

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 h

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-20 03:48

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

提交回复
热议问题