
mongdb
浮生若梦l
全栈
展开
-
mongodb删除数据,释放磁盘内存
1.db.getCollection("").deleteMany({"createTime":{$lt:1604201566}})//条件删除2.db.getCollection("texttime").update({"createTime":{$lt:1603763728}},{ $set: {"createAA": new Date()} },false,true)//ttl删除3.db.runCommand({closeAllDatabases:1})//释放mongodb数据,此时lin原创 2021-02-19 09:54:05 · 1879 阅读 · 1 评论 -
mongodb 分片模式以及操作增删改查
1.启动数据库分片:db.runCommand( { enablesharding : "xx库" } );或 sh.enableSharding()2.分片模式下,进行集合分片有两种方式:基于范围:sh.shardCollection("dbname.colname",{key:1}) 基于hash:sh.shardCollection("dbname.colname",{key:"hashed"})3.查询分片状态:db.stats()4.进行分片的colname集合,进行单个数据修改.原创 2021-01-21 13:28:07 · 367 阅读 · 0 评论 -
mongodb 正则-不区分大小写匹配
1.正则查询 不区分大小写 i,设置开始字段 ^,结束字段$,其中某段匹配任意字段.*{"name" : { "$regex" : "^lslad.*cn$", "$options" : "i" } }或者{ "name" :/^lslad.*cn$/i }2.踩坑记录java中使用正则查询{ "name" :/^lslad.*cn$/i },是不生效的,打印出来是{ "name" :"/^lslad.*cn$/i"},有引号,所以,只能用{"name" : { "$regex" :...原创 2020-12-25 17:56:39 · 1439 阅读 · 2 评论 -
sort operation used more than the maximum 33554432 bytes of RAM. Add an index,or specify a smaller
生产环境mongodb 报错,sort operation used more than the maximum 33554432 bytes of RAM. Add an index,or specify a smaller limit排序查询超过最大内存32兆,添加索引或者增加内存限制解决方法1、创建索引--不阻塞创建索引db.xxxxx.createIndex({"nam...原创 2020-02-25 11:59:11 · 565 阅读 · 0 评论 -
mongdb 统计 cannot run map reduce without the js engine' on server
解决办法一:修改mongdb配置文件1.vim /etc/mongod.conf2.将security: javascriptEnabled: false修改为security: javascriptEnabled: true原创 2020-01-11 18:12:20 · 488 阅读 · 0 评论 -
mongdb 建立地图索引,删除,查询
方式一:创建db.shop.ensureIndex( { loc : "2dsphere" } ) //2Dsphere索引,用于存储和查找球面上的点。db.shop.ensureIndex( { loc : "2d" } ) //2D索引,用于存储和查找平面上的点。查询db.getCollection('user').getIndexes()删除db.user.dro...原创 2020-01-11 14:41:07 · 187 阅读 · 0 评论 -
mongdb 数字转换异常
java bean中的主键id策略默认为ObjectId,若此时主键为int等类型,将无法转换,报错!解决方式一:将java bean中主键改为ObjectId解决方式二:更改mongdb主键生成策略为int自增长,需要做处理,可百度。...原创 2019-05-20 15:59:48 · 210 阅读 · 0 评论 -
mongdb副本集(How to Create Highly Available MongoDB Databases with Replica Sets)
One of the most common ways to create a high-availability MongoDB database, such asApsaraDB for MongoDB, is by using replica sets. A MongoDB replica set is composed of a group of MongoDB instances (p...转载 2019-06-26 12:36:15 · 201 阅读 · 0 评论 -
morphia 正则查询(Pattern忽略大小写查询)
1.方式一:db.exists("account", Pattern.compile(example.getAccount(),Pattern.CASE_INSENSITIVE))原创 2019-09-07 16:30:10 · 199 阅读 · 0 评论