unauthorized db lock type:-1

眉间皱痕 提交于 2019-12-06 13:20:39

I wrote a simple repro but didn't have any problem running it successfully.

public static void main(String[] args) throws UnknownHostException, MongoException {
    Mongo mongo = new Mongo();
    DB db = mongo.getDB("test");
    boolean auth = db.authenticate("scott", "scott".toCharArray());
    DBCollection coll = db.getCollection("myWords");
    DBObject dbObj = (DBObject) JSON.parse("{ \"_id\" : 1.0 , \"words\" : [ \"a\" , \"b\" , \"c\"] , \"score\" : 1.1 , \"data\" : \"foo\"}");
    coll.insert(dbObj);
    System.out.print(coll.findOne().toString());

    Morphia morphia = new Morphia();
    Datastore datastore = morphia.createDatastore(mongo, "test");
    Word w = datastore.find(Word.class).get();
    System.out.print(w);

}

@Entity("myWords")
static class Word {
    @Id Double id;
    ArrayList<String> words = new ArrayList<String>();
    Double score;
    String data;

    @Override
    public String toString() {
        return this.id.toString();
    }


}

Which resulted in this:

{ "_id" : 1.0 , "words" : [ "a" , "b" , "c"] , "score" : 1.1 , "data" : "foo"} 
...
1.0

Which seems like the correct thing. Can you run this code, but substitute your db/user/password?

I am getting the same issue with Mongolab.

org.springframework.data.mongodb.UncategorizedMongoDbException: unauthorized db:bacon lock type:-1 client:YYY; nested exception is com.mongodb.MongoException: unauthorized db:bacon lock type:-1 client:YYY org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:70) org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:1538)

If it's local it could be firewall issue on the PC, Router or Cable provider.

FIXED For me, McAfee Host Intrusion Prevention (McAfeeFire.exe) required a rule for STS.exe and Java to be able to access remote hosts like Mongolab. That worked!

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