设为首页 加入收藏

TOP

MongoDB 最近遇到的几个小问题(一)
2019-09-17 18:16:39 】 浏览:47
Tags:MongoDB 最近 遇到 问题

(1)连接数据库时报错

ERROR Topshelf.Hosts.ConsoleRunHost.Run 1 
An exception occurred
System.TimeoutException: A timeout occured after 30000ms selecting a server using CompositeServerSelector

错误原因是和转义字符有关。连接字符串使用的URL格式,所以其中的密码中的% 需要转义。

知识扩展:

连接mongo使用URI有特殊字符 '@' 或者":"或者‘%’, 连接会报错,需要进行转义。

解决方法:

把 @ 换成 %40 

把 : 换成 %3A

把 % 换成 %25

 (2)时间字段的范围查询,请注意时间字段的类型。

例如,明看到集合中指定时间段内有数据,但是Count结果还是显示为0。

最早的一笔数据是20170816,但是使用以下语句查询2017-08-14 到 2018-08-18时间段内的文档数据为0.

 

问题在哪儿哪? 

查看发现query.time字段类型是 string.

我们将查询语句的条件格式转换为字段的存储格式,就OK了。

 

所以,在设计集合模式时,要特别注意存储日期时间的字段的类型,建议为Date。另外,查询时也要小心,防止数据异常。

(3)副本集添加节点时报错

错误信息:

{
    "ok" : 0,
    "errmsg" : "Quorum check failed because not enough voting nodes responded; required 2 but only the following 1 voting nodes responded: 172.XXX.XXX.XXX:27017; the following nodes did not respond affirmatively: 172.XXX.XXX.XX:27017 failed with No route to host",
    "code" : 74,
    "codeName" : "NodeNotFound"
}

错误原因是:防火墙没关闭 导致

(4)将常规集合设置为固定集合,既有的索引丢失,需要重建。

db.runCommand({"convertToCapped": "集合名字", size: XXXXXX,"max":XXXXX});

设置为固定集合后,原来的索引都丢失了,需要谨记 。

(曾经的一个转换性能测试,及转为固定集合的耗时:1001 W数据,16.8 G 约耗时 6分钟)

(5)mongodb 对字段中有超过 1024 字节的不会建立索引

MongoDB will not create an index on a collection if the index entry for an existing document exceeds the index key limit (1024 bytes). You can however create a hashed index or text index instead:

除了上面的介绍外,还可以修改启动配置参数 ailIndexKeyTooLong。

(6)配置分片的复制集需,在启动的配置文件中需 指定 shardsvr参数。否则,在启动数据库分片时报错。

错误信息如下:

在config文件中,添加 shardsvr=true 即可。

重启服务,再次启动启动分片,执行OK.

 

(7)MongoDB 服务异常关闭, the process must exit and restart

查看实例的运行log,报错信息如下:

2019-06-16T04:54:54.830+0800 E STORAGE  [thread2] WiredTiger error (28) [1560632094:830160][160893:0x7f2b30e80700], file:WiredTiger.wt, WT_SESSION.checkpoint: /data/mongodb/XXXXXXXXXXX/data/db/WiredTiger.turtle.set: handle-write: pwrite: failed to write 1015 bytes at offset 0: No space left on device
2019-06-16T04:54:54.830+0800 E STORAGE  [thread2] WiredTiger error (28) [1560632094:830727][160893:0x7f2b30e80700], file:WiredTiger.wt, WT_SESSION.checkpoint: /data/mongodb/XXXXXXXXXXX/data/db/WiredTiger.turtle.set: handle-write: pwrite: failed to write 1015 bytes at offset 0: No space left on device
2019-06-16T04:54:54.830+0800 E STORAGE  [thread2] WiredTiger error (0) [1560632094:830818][160893:0x7f2b30e80700], file:WiredTiger.wt, WT_SESSION.checkpoint: WiredTiger.turtle: encountered an illegal file format or internal value
2019-06-16T04:54:54.830+0800 E STORAGE  [thread2] WiredTiger error (-31804) [1560632094:830848][160893:0x7f2b30e80700], file:WiredTiger.wt, WT_SESSION.checkpoint: the process must exit and restart: WT_PANIC: WiredTiger library panic
2019-06-16T04:54:54.830+0800 I -        [thread2] Fatal Assertion 28558 at src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp 361
2019-06-16T04:54:54.830+0800 I -        [thread2] 

***aborting after fassert() failure


2019-06-16T04:54:54.875+0800 F -        [thread2] Got signal: 6 (Aborted).

 0x56500f890ee1 0x56500f88ffd9 0x56500f8904bd 0x7f2b378945e0 0x7f2b374f71f7 0x7f2b374f88e8 0x56500eb24d79 0x56500f59e366 0x56500eb2f329 0x
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇CentOS7.x卸载与安装MySQL5.7的操.. 下一篇oracle自增主键

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目