
mongo
文章平均质量分 73
全栈
从事软件开发工作多年,拥有较为丰富的开发经验,主导多个大型项目的研发工作,丰富的项目经验。
设计软件架构和撰写软件方案等。
展开
-
mongo 4.0安装
官网4.0~ 安装https://docs.mongodb.com/v4.0/tutorial/install-mongodb-on-ubuntu/如果报缺库mongodb-org-server : Depends: libcurl3 (>= 7.16.2) but it is not going to be installed执行sudo apt-get insta...原创 2020-03-03 18:49:08 · 301 阅读 · 0 评论 -
跟我一起学mongo : mongo 修改语句某一个字段,加一个前缀
db.getCollection('userinfo').find({"sex":"1"}).forEach( function(item){ db.getCollection('userinfo').update({"_id":item._id},{$set:{"name": "back_up"+item.name}})...原创 2020-01-16 14:58:22 · 1054 阅读 · 0 评论 -
启动 mongo 指定配置文件
sudo mongod -f /etc/mongod.conf &原创 2019-09-26 11:24:11 · 585 阅读 · 0 评论 -
mongodb-org-server : Depends: libcurl3 (>= 7.16.2) but it is not going to be installed
错误信息sudo apt-get install mongodb-org-serverReading package lists... DoneBuilding dependency tree Reading state information... DoneSome packages could not be installed. This may mean th...原创 2019-09-05 13:55:45 · 7044 阅读 · 4 评论 -
mongo 备份
备份mongodump -h dbhost -d dbname -o dbdirectory还原目录/home/thkadmindb/thkadmindbmongorestore -h localhost -d publicDB /home/thk/164/dump/publicDB原创 2019-08-25 06:23:48 · 173 阅读 · 0 评论 -
mongodb 查询优化 主要针对count慢
数据 1800万 数据一直增加中优化前 耗时:7.9s(未加索引,查询时CPU飞了)filter = bson.D{{"userid", userid}, {"height", height}}Txs, err := c.Mgo.Collection(m.UserTxs).Find(context.Background(), filter, opts)sCount, err := c...原创 2019-07-06 15:11:31 · 22389 阅读 · 5 评论 -
go gin 使用jwt 鉴权
本博客代码已发布在github:https://github.com/Huochengyan/myGoProject第一步: 服务器生成Token package apiimport ( "github.com/astaxie/beego/validation" "github.com/gin-gonic/gin" "log" "myProject/corll" ...原创 2019-06-28 15:35:49 · 2978 阅读 · 0 评论 -
golang 分页获取mongodb数据
分页查询:/* 分页获取用户 */func (c *UserC) GetALLUserByPage(g *gin.Context) { rsp := new(Rsp) var info PostParamTx err := g.BindJSON(&info) if err != nil { rsp.Msg = "json faild" rsp.Code = 201...原创 2019-06-28 15:25:44 · 4045 阅读 · 0 评论 -
golang $or $in $ge $gte 查询使用
1. 范围查询: 类似sql: between and ... ( 30<x<40 ) 举例: filter := bson.D{{"cid", cid}, {"height", bson.M{"$gte": startheight, "$lt": endheight}}}2.包含查询: 类似sql: where id in(........原创 2019-06-27 16:20:14 · 2470 阅读 · 0 评论 -
go 2. 记录一次恶心使用 $or golang mongo
直接代码:想实现类似sql where nickname="张三" sex=1or sex=2 的效果。mongo官方的例子使用一直报错。查资料呗。终于找到,这里记录下。filter=bson.D{{"nickname","张三"},{"$or",[]interface{}{bson.D{{"sex",1}},bson.D{{"sex",2}}}}}...原创 2019-06-12 16:20:23 · 1964 阅读 · 3 评论 -
mongo 创建索引
三种方式:方式一:使用可视化工具Robo 3T 创建右键 选择add index 添加索引如下图:方式二:脚本创建:db.test.createindex({"phone":1})方式三:使用代码创建:db.collection.indexs().create({})//两个字段关联 ,创建唯一索引_, err = mongoCl...原创 2019-05-17 18:41:16 · 1697 阅读 · 2 评论 -
mongo索引加速查询
实验前:func TestInsert(g *gin.Context) { rsp := new(Rsp) var tests [] interface{} for i:=0; i<1000000 ;i++ { newuser := new(Test) newuser.Email =strconv.Itoa(i) newuser.Username =strco...原创 2019-05-15 15:18:22 · 298 阅读 · 0 评论