Mongo java抱怨说高手不是高手

时间:2015-12-24 17:55:10

标签: mongodb

我遇到了这个例外:

Caused by: com.mongodb.CommandFailureException: { "serverUsed" : "twig09.twigs:27017" , "note" : "from execCommand" , "ok" : 0.0 , "errmsg" : "not master"}
        at com.mongodb.CommandResult.getException(CommandResult.java:76) ~[stormjar.jar:?]
        at com.mongodb.CommandResult.throwOnError(CommandResult.java:140) ~[stormjar.jar:?]
        at com.mongodb.DBCollectionImpl.createIndex(DBCollectionImpl.java:399) ~[stormjar.jar:?]
        at com.mongodb.DBCollection.createIndex(DBCollection.java:597) ~[stormjar.jar:?]
        at com.mongodb.DBCollection.ensureIndex(DBCollection.java:726) ~[stormjar.jar:?]

然而,twig09是主人。

tbx0:PRIMARY> rs.isMaster()
{
    "setName" : "tbx0",
    "setVersion" : 2,
    "ismaster" : true,
    "secondary" : false,
    "hosts" : [
        "twig09.twigs:27017",
        "twig11.twigs:27017"
    ],
    "primary" : "twig09.twigs:27017",
    "me" : "twig09.twigs:27017",
    "electionId" : ObjectId("567c25829fad8fd73b0f1630"),
    "maxBsonObjectSize" : 16777216,
    "maxMessageSizeBytes" : 48000000,
    "maxWriteBatchSize" : 1000,
    "localTime" : ISODate("2015-12-24T17:53:17.557Z"),
    "maxWireVersion" : 2,
    "minWireVersion" : 0,
    "ok" : 1
}

rs.status()
{
    "set" : "tbx0",
    "date" : ISODate("2015-12-24T19:49:53Z"),
    "myState" : 1,
    "members" : [
        {
            "_id" : 0,
            "name" : "twig09.twigs:27017",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "uptime" : 84385,
            "optime" : Timestamp(1450891173, 1),
            "optimeDate" : ISODate("2015-12-23T17:19:33Z"),
            "electionTime" : Timestamp(1450976642, 1),
            "electionDate" : ISODate("2015-12-24T17:04:02Z"),
            "self" : true
        },
        {
            "_id" : 1,
            "name" : "twig11.twigs:27017",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 9957,
            "optime" : Timestamp(1450891173, 1),
            "optimeDate" : ISODate("2015-12-23T17:19:33Z"),
            "lastHeartbeat" : ISODate("2015-12-24T19:49:51Z"),
            "lastHeartbeatRecv" : ISODate("2015-12-24T19:49:52Z"),
            "pingMs" : 0,
            "syncingTo" : "twig09.twigs:27017"
        }
    ],
    "ok" : 1
}

这是mongo 2.6,驱动程序2.13

Mongo对象用Spring中的MongoTemplate包装。

Mongo配置了mongo.setReadPreference(ReadPreference.nearest());但是,我不认为这是相关的,因为createIndex()是失败的方法。

这是一个错误吗?我错过了什么吗?

0 个答案:

没有答案