mongodb 两个错误处理

mongos> db.person.remove()
Thu May 23 11:47:51.308 JavaScript execution failed: getlasterror failed: {
        "shards" : [
                "shard1/127.0.0.1:10000,127.0.0.1:10001,127.0.0.1:10002",
                "shard2/127.0.0.1:20000,127.0.0.1:20001,127.0.0.1:20002",
                "shard3/127.0.0.1:30000,127.0.0.1:30001,127.0.0.1:30002"
        ],
        "ok" : 0,
        "errmsg" : "could not get last error from a shard shard3/127.0.0.1:30000,127.0.0.1:30001,127.0.0.1:30002 :: caused by :: DBClientBase::findN: transport error: 127.0.0.1:30002 ns: test.$cmd query: { getlasterror: 1.0, w: 1.0 }"
} at src/mongo/shell/db.js:L698
mongos> db.person.count()
Thu May 23 11:50:40.491 JavaScript execution failed: count failed: {
        "code" : 10009,
        "ok" : 0,
        "errmsg" : "exception: ReplicaSetMonitor no master found for set: shard3"
} at src/mongo/shell/query.js:L180
mongos> db.person.drop()
Thu May 23 11:51:53.059 JavaScript execution failed: drop failed: {
        "code" : 10009,
        "ok" : 0,
        "errmsg" : "exception: ReplicaSetMonitor no master found for set: shard3"
} at src/mongo/shell/collection.js:L383

 这是错误表示服务器死了,在linux下用ps -ef|grep mongod查看mongodb的在linux进程,查看那台服务器死了。重新启动服务器后就没事了。

error preparing documents for insert :: caused by :: tried to insert object with no valid shard key for { id: 1.0 } : { _id: ObjectId('519b4094a213ce733bd63abd'), name: "test" }

  这个错误表示要指定分片的键。

分片的键表示:添加数据的时候必要有这个键作为字段。是否添加不成功!

也就是如下操作:

db.runCommand({shardcollection:"test.c1",key:{id:1}})

 这里指定的key(键)是id,那么添加数据的时候,就必须要有字段id。否则添加不成功!

自己在使用的过程中遇到的错误,如果有新的错误及时添加上。

相关推荐