当前位置:网站首页>Mangodb simple to use
Mangodb simple to use
2022-07-27 09:00:00 【MG-net】
One 、 brief introduction
1、 Data model :


At the same time, some scripts can be used for logical processing
2、 characteristic
- High performance
- High availability
- High expansion
- Rich query methods
- Modeless , The data structure is relatively loose (BSON Storage )
3、 Related contents of the configuration file
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data. The logging stored
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data. Data storage location
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# wiredTiger:
# how the process runs Background operation
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
# timeZoneInfo: /usr/share/zoneinfo
# network interfaces The binding of IP and port Bind lan IP
net:
port: 27017
bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
Two 、 Basic operation
1、 Database creation and deletion
Create database :use dbname, It should be noted that , Databases without collections exist only in memory .
Delete database :db.dropDataBase()
2、 The basic operation of a set
stay mangobd in , Set is equivalent to the table structure of relational database . Creation is divided into implicit 、 Create explicitly .
Explicit creation is to create a table without data , Implicit creation is to directly create a table when inserting data .
- Single insert :db.comment.insert({"id":"1","content":" test "})

- Batch insert :db.comment.insertMany([{"id":"2","content":" test 2","f":"123"},{"id":"3","content":" test 3","y":"123"}]), When the insertion fails , have access to try{}catch{}

- Query all :db. aggregate .find()
- Conditions of the query :db. aggregate .find({"id":"123"})
- Look up a :db. aggregate .findOne( Conditions )
- Projection query :db. aggregate .find({"id":"123"}, {"content":1, "id":0})
- to update :db. aggregate .update(query,update,options)
- Covering the update :db.comment.update({id:"1"}, {f:NumberInt(2)})
- Partial update :db.comment.update({id:"2"}, {$set:{f:NumberInt(3)}})
- Batch update :db.comment.update({id:"2"}, {$set:{f:NumberInt(3)}}, {multi:ture})
- Column value growth :db.comment.update({id:"2"}, {$inc:{f:NumberInt(1)}})
- Delete :db. aggregate .remove( Conditions )
- Statistics query :db. aggregate .count( Conditions )
- Paging query :db. aggregate .find().skip(2).limit(2), Second page each page 2 That's ok skip from 0 How many bars start jumping
- Sort query :db. aggregate .find().sort({ Field :1}),1 Ascending 、-1 Descending
- Regular expression queries :db.comment.find({content:/2/})
- Comparison query :db. aggregate .find({ Field :{$gt:700}})
- Contains the query :db. aggregate .fund({ Field :{$in:[v1,v2]}})
- Conditions of the query :$and、$or,db.comment.find({$and:[{f:{$gt:2}}, {id:{$gt:2}}]})
3、 Indexes -Index
Index is to improve efficiency , Full set scan without index .mongoDB When index is used B-Tree.
Type of index :
- Single field index : Add an index to a field

- Composite index : Index of multiple fields

- Other indexes : Geospatial index 、 Text index 、 Hash index
Index management
- see :db. aggregate .getIndexes()
- establish :db. aggregate .createIndex(keys, options),keys Is to add an indexed field ,options as follows

- remove :
- db. aggregate .dropIndex( The index name \ Conditions ):db.comment.dropIndex({content:-1})
- Delete all indexes :db.comment.dropIndexs()
Implementation plan :
Used to analyze the execution performance of query statements .db.comment.find({f:2}).explain(), Use Compass Check more clearly :

After adding the index :

Cover queries : When the query condition and query projection only contain index fields , Return results directly from the index , It's very efficient .

边栏推荐
- “蔚来杯“2022牛客暑期多校训练营1
- linux安装和远程连接mysql记录
- Interface test tool - JMeter pressure test use
- Mangodb简单使用
- New year's goals! The code is more standardized!
- 1.3.1 Full Permutation Problem
- [I2C reading mpu6050 of Renesas ra6m4 development board]
- 8 kinds of visual transformer finishing (Part 1)
- 博客怎么上传动态gif图
- JS detects whether the client software is installed
猜你喜欢

CUDA programming-04: CUDA memory model

The following license SolidWorks Standard cannot be obtained, and the use license file cannot be found. (-1,359,2)。

General Administration of Customs: the import of such products is suspended

微信安装包从0.5M暴涨到260M,为什么我们的程序越来越大?

BEVFormer: Learning Bird’s-Eye-View Representation from Multi-Camera Images via Spatiotemporal Trans

NIO this.selector.select()

flex布局 (实战小米官网)

Aruba learning notes 10 security authentication portal authentication (web page configuration)

Mmrotate trains its dataset from scratch

网络IO总结文
随机推荐
4278. 峰会
ctfshow 终极考核
Pytorch custom CUDA operator tutorial and runtime analysis
PVT的spatial reduction attention(SRA)
Low cost, low threshold, easy deployment, a new choice for the digital transformation of 48 million + small and medium-sized enterprises
691. Cube IV
3311. 最长算术
【微服务~Sentinel】Sentinel之dashboard控制面板
Include error in vs Code (new header file)
A survey of robust lidar based 3D object detection methods for autonomous driving paper notes
Matlab求解微分代数方程 (DAE)
E. Split into two sets
微信安装包从0.5M暴涨到260M,为什么我们的程序越来越大?
Digital intelligence innovation
【进程间通信IPC】- 信号量的学习
async/await的执行顺序以及宏任务和微任务
Unity3d 2021 software installation package download and installation tutorial
4279. 笛卡尔树
Full Permutation (depth first, permutation tree)
HUAWEI 机试题:字符串变换最小字符串 js